Python's math functions

 

 You need to import modules (built-in function)

function Return Value (description)
abs(x) Returns the absolute value
max(x1, x2,...) The maximum value, the parameter may be a sequence.
(x1, x2, ...) The minimum value, the parameter may be a sequence.
pow (x, y) power
round(x [,n]) Rounding, n represents rounded to the digits after the decimal point.

 

 

 

 

math module

You need to import math module, and then math. Constants way name / function name called.

 

Constants, functions Return Value (description)
e

Mathematical constant e

pi

Fr.

   

sin (x), cos (x), tan (x)

x is in radians

degrees(x)

Radian angle turn
radians(x)  Degrees to radians
   
pow (x, y) x power of y
exp(x)

e power of x

sqrt(x) Open square arithmetic
   
fabs(x) Absolute value
fmod Modulo remainder
fsum(seq) Sequence summing
   
ceil(x) Improvement ToSei
floor Rounding down
   
log(x,base) Logarithm to the base as a bottom, x is
log2(x) Base 2 logarithm, x is
log10(x) Logarithm to the base 10, x is

 

 

Sequence refers to a list (List), tuples (Tuple), string (String).

Sequence, is ordered, the set (Set) is a disorder, not a sequence.

 

Above functions will not change the value of the parameter itself.

 

 

 

 

random module

We need to import the random module, and then to call the module name.

function Description (return value)
random() A random number between [0,1)
randint(start,end) [Start, end] on an integer, comprising max. By then you can multiply and divide to get a float.
uniform(start,end) A real number on [start, end]
randrange(start,end,step) It returns a random number in the specified number. For example (0,100,5), at 0,5,10, ..., 100 returns a random number.
choice(seq) A random number sequence returned from
shuffle(seq) The random ordering of the sequence (upset)
seed(x) Set seed, defaults to the current time

 

Guess you like

Origin www.cnblogs.com/chy18883701161/p/11285491.html