Python - Numbers: Var1 1 Var2 10
Python - Numbers: Var1 1 Var2 10
Python - Numbers: Var1 1 Var2 10
Advertisements
Number data types store numeric values. They are immutable data types, means that changing the value of a
number data type results in a newly allocated object.
Number objects are created when you assign a value to them. For example −
var1 = 1
var2 = 10
You can also delete the reference to a number object by using the del statement. The syntax of the del statement is
−
del var1[,var2[,var3[....,varN]]]]
You can delete a single object or multiple objects by using the del statement. For example −
del var
del var_a, var_b
int signedintegers − They are often called just integers or ints, are positive or negative whole numbers
with no decimal point.
long longintegers − Also called longs, they are integers of unlimited size, written like integers and followed
by an uppercase or lowercase L.
float f loatingpointrealvalues − Also called floats, they represent real numbers and are written with a
decimal point dividing the integer and fractional parts. Floats may also be in scientific notation, with E or e
indicating the power of 10 (2.5e2 = 2.5 x 102 = 250).
complex complexnumbers − are of the form a + bJ, where a and b are floats and J orj represents the
square root of -1 whichisanimaginarynumber. The real part of the number is a, and the imaginary part is
b. Complex numbers are not used much in Python programming.
Examples
Python allows you to use a lowercase L with long, but it is recommended that you use only an uppercase L
to avoid confusion with the number 1. Python displays long integers with an uppercase L.
A complex number consists of an ordered pair of real floating point numbers denoted by a + bj, where a is
the real part and b is the imaginary part of the complex number.
Type complexx to convert x to a complex number with real part x and imaginary part zero.
Type complexx, y to convert x and y to a complex number with real part x and imaginary part y. x and y
are numeric expressions
Mathematical Functions
Python includes following functions that perform mathematical calculations.
1 absx
2 ceilx
3 cmpx, y
-1 if x < y, 0 if x == y, or 1 if x > y
4 expx
The exponential of x: ex
5 fabsx
6 floorx
7 logx
8 log10x
9 maxx1, x2, . . .
10 minx1, x2, . . .
11 modfx
The fractional and integer parts of x in a two-item tuple. Both parts have the same sign as x. The
integer part is returned as a float.
12 powx, y
13 roundx[, n]
x rounded to n digits from the decimal point. Python rounds away from zero as a tie-breaker: round
0.5 is 1.0 and round−0.5 is -1.0.
14 sqrtx
1 choiceseq
3 random
A random float r, such that 0 is less than or equal to r and r is less than 1
4 seed[x]
Sets the integer starting value used in generating random numbers. Call this function before calling
any other random module function. Returns None.
5 shufflelst
6 uniformx, y
A random float r, such that x is less than or equal to r and r is less than y
Trigonometric Functions
Python includes following functions that perform trigonometric calculations.
1 acosx
2 asinx
3 atanx
4 atan2y, x
5 cosx
6 hypotx, y
7 sinx
8 tanx
9 degreesx
Mathematical Constants
The module also defines two mathematical constants −
1
pi
2
e