Chapter 3 python3, python3
Mathematical functions
Function |
Return Value (description) |
Abs (x) |
Returns the absolute value of a number. For example, abs (-10) returns 10. |
Ceil (x) |
Returns the upper integer of a number. For example, math. ceil (4.1) returns 5. |
Cmp (x, y) |
If x <y returns-1, if x = y returns 0, if x> y returns 1.Python 3 is obsolete. UseUse (x> y)-(x <y)Replace. |
Exp (x) |
Returns the x power of e (ex). For example, math. exp (1) returns 2.718281828459045 |
Fabs (x) |
Returns the absolute value of a number. For example, math. fabs (-10) returns 10.0 |
Floor (x) |
Returns the rounded down integer of a number. For example, math. floor (4.9) returns 4. |
Log (x) |
For example, math. log (math. e) returns 1.0, math. log (2.0) returns |
Log10 (x) |
Returns the logarithm of x on the base of 10. For example, math. log10 (100) returns 2.0. |
Max (x1, x2 ,...) |
Returns the maximum value of a given parameter, which can be a sequence. |
Min (x1, x2 ,...) |
Returns the minimum value of a given parameter, which can be a sequence. |
Modf (x) |
Returns the integer and decimal parts of x. The numerical symbols of the two parts are the same as those of x, and the integer part is expressed as a floating point. |
Pow (x, y) |
The value after the x ** y operation. |
Round (x [, n]) |
Returns the rounding value of floating point x. If n is given, it indicates the number of digits rounded to the decimal point. |
Sqrt (x) |
Returns the square root of x. |
Random Number Function
Random numbers can be used in mathematics, games, security, and other fields. They are often embedded in algorithms to improve algorithm efficiency and program security.
Function |
Description |
Choice (seq) |
Randomly select an element from the element of the sequence, such as random. choice (range (10), and randomly select an integer from 0 to 9. |
Randrange ([start,] stop [, step]) |
Obtains a random number from a set that increments by the specified base number within the specified range. The default value of the base number is 1. |
Random () |
The next real number is randomly generated within the range of [0, 1. |
Seed ([x]) |
Change the seed of the random number generator. If you do not understand the principle, you do not need to set seed. Python will help you select seed. |
Shuffle (lst) |
Random sorting of all elements in a sequence |
Uniform (x, y) |
The next real number is randomly generated, which is within the range of [x, y. |
Trigonometric function
Function |
Description |
Acos (x) |
Returns the arc cosine radians of x. |
Asin (x) |
Returns the arc sine radians of x. |
Atan (x) |
Returns the arc tangent radians of x. |
Atan2 (y, x) |
Returns the arc tangent of the given X and Y coordinate values. |
Cos (x) |
Returns the cosine of the radians of x. |
Hypot (x, y) |
Returns the euclidean norm sqrt (x * x + y * y ). |
Sin (x) |
Returns the sine of x radians. |
Tan (x) |
Returns the tangent of x radians. |
Degrees (x) |
Converts radians to degrees. For example, if degrees (math. pi/2), 90.0 is returned. |
Radians (x) |
Converts degrees to radians. |
Mathematical constants
Constant |
Description |
Pi |
Mathematical constant pi (circumference rate, usually expressed by π) |
E |
Mathematical constants e, e are natural constants (natural constants ). |