2. A complex number consists of anordered pair of realfloatingpoint numbers denoted by a + bj, where a is
the realpart and b is the imaginary part of the complex number.
Number Type Conversion:
Pythonconverts numbers internally inanexpressioncontaining mixed types to a commontype for evaluation. But
sometimes, you'llneed to coerce a number explicitly fromone type to another to satisfy the requirements of an
operator or functionparameter.
Type int(x)to convert x to a plaininteger.
Type long(x) to convert x to a long integer.
Type float(x) to convert x to a floating-point number.
Type complex(x) to convert x to a complex number withrealpart x and imaginary part zero.
Type complex(x, y) to convert x and y to a complex number withrealpart x and imaginary part y. x and
y are numeric expressions
Mathematical Functions:
Pythonincludes following functions that performmathematicalcalculations.
Function Returns ( description )
abs(x) The absolute value of x: the (positive) distance betweenx and zero.
ceil(x) The ceiling of x: the smallest integer not less thanx
cmp(x, y) -1 if x < y, 0 if x == y, or 1 if x > y
exp(x) The exponentialof x: ex
fabs(x) The absolute value of x.
floor(x) The floor of x: the largest integer not greater thanx
log(x) The naturallogarithmof x, for x> 0
log10(x) The base-10 logarithmof x for x> 0 .
max(x1, x2,...) The largest of its arguments: the value closest to positive infinity
min(x1, x2,...) The smallest of its arguments: the value closest to negative infinity
modf(x) The fractionaland integer parts of x ina two-itemtuple. Bothparts have the same
signas x. The integer part is returned as a float.
pow(x, y) The value of x**y.
round(x [,n]) x rounded to ndigits fromthe decimalpoint. Pythonrounds away fromzero as a
tie-breaker: round(0.5) is 1.0 and round(-0.5) is -1.0.
sqrt(x) The square root of x for x > 0
Random Number Functions:
Randomnumbers are used for games, simulations, testing, security, and privacy applications. Pythonincludes
following functions that are commonly used.
3. Function Description
choice(seq) A randomitemfroma list, tuple, or string.
randrange ([start,] stop
[,step])
A randomly selected element fromrange(start, stop, step)
random() A randomfloat r, suchthat 0 is less thanor equalto r and r is less than1
seed([x]) Sets the integer starting value used ingenerating randomnumbers. Callthis
functionbefore calling any other randommodule function. Returns None.
shuffle(lst) Randomizes the items of a list inplace. Returns None.
uniform(x, y) A randomfloat r, suchthat x is less thanor equalto r and r is less thany
Trigonometric Functions:
Pythonincludes following functions that performtrigonometric calculations.
Function Description
acos(x) Returnthe arc cosine of x, inradians.
asin(x) Returnthe arc sine of x, inradians.
atan(x) Returnthe arc tangent of x, inradians.
atan2(y, x) Returnatan(y / x), inradians.
cos(x) Returnthe cosine of x radians.
hypot(x, y) Returnthe Euclideannorm, sqrt(x*x + y*y).
sin(x) Returnthe sine of x radians.
tan(x) Returnthe tangent of x radians.
degrees(x) Converts angle x fromradians to degrees.
radians(x) Converts angle x fromdegrees to radians.
Mathematical Constants:
The module also defines two mathematicalconstants:
Constants Description
pi The mathematicalconstant pi.
e The mathematicalconstant e.