Python Learning Note--python number (numeric)

Source: Internet
Author: User

Python Number Type Conversion
int (x, y)#converts x to an integer and y to the binary number. such as int (' 11 ', 2) converts the binary number 11 to an integer of decimal number, the result is 3Long (x, y)#convert x to a long integerFloat (x)#convert x to a floating-point numberComplex (real [, Imag])#Create a complex numberSTR (x)#convert an object x to a stringREPR (x)#convert an object x to an expression stringeval (str)#used to evaluate a valid Python expression in a string and return an objectTuple (s)#Converting a sequence s to a tupleList (s)#Convert the sequence s to a listChr (x)#converts an integer to one character. such as Chr (100), the result is DUNICHR (x)#converts an integer to a Unicode characterOrd (x)#converts a character to its integer value. such as Ord (' B '), the result is 98, and B is converted to ASCII valueHex (x)#converts an integer to a hexadecimal stringOct (x)#converts an integer to an octal string
Python math functions
#function #返回值 (description)ABS (x)#returns the absolute value of a number, such as ABS (-10)Ceil (x)#returns the top integer of a number, such as Math.ceil (4.1) returns 5CMP (x, y)#If x < y returns 1, if x = = y returns 0, if x > y returns 1EXP (x)#returns the x power of E (ex), such as MATH.EXP (1) returns 2.718281828459045Fabs (x)#returns the absolute value of a number, such as Math.fabs (-10) to return 10.0Floor (x)#returns the lower integer of a number, such as Math.floor (4.9) returns 4Log (x)#if Math.log (MATH.E) returns 1.0,math.log (100,10) return 2.0LOG10 (x)#returns the logarithm of x with a base of 10, as MATH.LOG10 (100) returns 2.0Max (x1, x2,...)#returns the maximum value of a given parameter, which can be a sequence. Min (x1, x2,...)#returns the minimum value for a given parameter, which can be a sequence. MODF (x)#returns the integer portion of x and the fractional part, the two-part numeric symbol is the same as x, and the integer part is represented by a floating-point type. Pow (x, y)# the value after the x**y operation. Round (x [, N])#returns the rounded value of the floating-point number x, if given an n value, that represents the digits rounded to the decimal point. sqrt (x)#returns the square root of a number x
Python random number 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:

# function    #描述choice (seq)    # pick an element randomly from the elements of the sequence, such as Random.choice (range (10)), and randomly pick an integer from 0 to 9.                
Randrange ([Start,] stop [, step])   # gets a random number in the collection that increments by the specified cardinality from within the specified range, and the base default value is 1random ()    # randomly generates the next real number, which is within the [0,1] range. seed ([x])   # changes the seeding seed of the random number generator. If you don't know how it works, you don't have to specifically set Seed,python to help you choose Seed. Shuffle (LST)    # randomly sorts all elements of a sequence uniform (x, y)    # randomly generates the next real number, which is in [X, Y] In the range.                                        
Python Trigonometric functions
#function #描述ACOs (x)#returns the inverse cosine radian value of x. 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)#converts radians to angles, such as degrees (MATH.PI/2), returning 90.0Radians (x)#convert an angle to radians

This article was reproduced in: http://www.runoob.com/python/python-numbers.html

Python Learning Note--python number (numeric)

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.