Python number rules and built-in functions

Source: Internet
Author: User
Tags mathematical functions square root

Python string Additions:

The string object must be treated as a parameter (non-str.capitalize () Form):

1.str (obj)--Converting an object to a string

2.len (str)-Calculate string length

3.max (str)--Returns the largest letter in a string

4.min (str)--Returns the smallest letter in a string

Python Numeric type conversions

1.int (x) converts x to integers

2.float (x) converts x to a floating-point number

Python arithmetic operations

+-*/Direct Write

% redundancy

* * exponentiation, such as 2**3=8, meaning 2 of the 3-time Square

Mathematical functions

1.abs (x)--Returns the absolute value

2.ceil (x)--Returns the integer of the number, as Math.ceil (4.1) returns 5

3.floor (x)--Returns the lower integer of the number, as Math.floor (4.7) returns 4

4.exp (x)--Returns the x power of E (ex), such as MATH.EXP (1) returns 2.718281828459045

5.log (x)--Returns the logarithm, such as Math.log (MATH.E) return 1.0,math.log (100,10) return 2.0

6.LOG10 (x)-Returns the logarithm of an X with a base of 10

7.fabs (x)--Returns the absolute value of a number of floating-point types, such as Math.fabs (-10) returns 10.0

8.max (X1,X2)--Returns the maximum value of a given parameter, which can be a sequence

9.min (X1,X2)--Returns the minimum value of the given parameter, which can be a sequence

10.MODF (x)-Returns the integer part and fractional part of X, the same as x, and the integer part as a floating-point number

11.pow (x, y)-Returns the Y-square of X (X**y)

12.round (X[,n])-Returns the rounded value of x, if n is given, n indicates the number of digits rounded to the decimal point

13.SQRT (x)--Returns the square root of x, e.g. MATH.SQRT (4) returns 2.0

Random function

Random numbers can be used in mathematics, games, security and other fields, but also often embedded in the algorithm to improve the efficiency of the algorithm and improve the security of the program.

Python contains the following common random number functions

(Note: The following functions require static calls to methods, such as Random.choice ())

1.choice ()-Selects an element randomly from the elements of a sequence, such as Random.choice (range (10)), and randomly selects an integer from 0 to 9.

2.randragne ([Start,]stop[,step])--Gets a random number from the specified range, in the collection incremented by the specified cardinality, and the base default value is 1.

3.random ()--take the number between [0,1]

4.seed ([x])--set seed, avoid pseudo-random, can not set

5.shuffle (list)-sorts all elements of a sequence randomly

6.uniform (x, y)--randomly generates a number between [X, Y] Range

Trigonometric function

ACOs (x) Returns the inverse cosine radian value of x. The parameter x is the cosine value must be between [ -1,1]
ASIN (x) Returns the arc value of the arc sine of X.
Atan (x) Returns the arc tangent value of x.
Atan2 (y, x) Returns the inverse tangent value of the given X and Y coordinate values.
COS (x) Returns the cosine of the arc of X.
Hypot (x, y) Returns Euclidean norm sqrt (x*x + y*y).
Sin (x) Returns the sine of the X radian.
Tan (x) Returns the tangent of x radians.
Degrees (x) Convert radians to angles, such as degrees (MATH.PI/2), returns 90.0
Radians (x) Convert an angle to radians

Python number rules and built-in functions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.