Python | Data Types | Numbers

Numbers are numeric data types used to store numeric values. Numbers can be integer and float.

Integer

An Integer int is a data type that stores positive or negative numeric values with no decimals or quotation marks.

An integer is defined the same way as a variable is declared. For example:

age = 40, number_of_students = 8

Float

A float is a data type that stores positive or negative numeric values with decimal parts.

A float is define the same way as a variable is declared. For example:

weight = 98.5, height = 1.86, average_grade = 8.95

Basic Numeric Functions

There are many numeric functions in Python but we will take a look just at a few of them.

abs(x)

The abs(x) function takes in a numeric value x and returns its absolute value (the positive distance between zero and the number). For example abs(-5) returns 5.

cmp(x,y)

The cmp(x,y) function takes in two numeric values x and y then returns -1 if x is less than y, 0 if x is equal to y, and 1 if x is greater than y.

pow(x,y) function takes in two numeric values x and y then returns the value of x to the power of y. In other words it is x ** y. For example pow(3,4) returns 81.

There are many more functions. You have to explore them!

Leave a Reply