Built-in functions and modules related to numbers in Python

Source: Internet
Author: User

Value Factory Function--

bool (obj) : Returns obj the Boolean value of the object, which is obj.__nonzero__ () The return value of the method.

int (obj,base=10) : Returns an integer representation of a string or numeric object , similar to string.atoi ()

long (obj,base=10) : Returns a long integer representation of a string or numeric object , similar to string.atol ()

float (obj) : Returns a floating-point representation of a string or numeric object, similar to String.atof () .

Complex (str) : Returns the plural representation of a string or numeric object.

Complex (real,imag=0.0) : Generates a complex object based on a given real number and an optional imaginary part.

Numeric Operation Function--

ABS (num) : Returns Num the absolute value.

coerce (num1,num2) : num1 num2

divmod (num1,num2) : The combination of division and take-rest operations, returns a tuple (num1/num2,num1%num2) .

Pow (num1,num2,mod=1): TakeNUM1of thenum2The second party, if providedMoDparameter, the result of the calculation is thenMoDtake the remainder operation.

round (flt,ndig=0) : Accept a floating-point number Flt and rounding it up, saving Ndig decimal place.

Integer conversion Function--

Hex (num) : Converts a number to a hexadecimal number and returns as a string.

Oct (num) : Converts a number to an octal number and returns as a string.

CHR (num) : ascii Span style= "Font-family:wenquanyi Micro Hei" >ascii character, range can only be Span style= "Font-family:wenquanyi Micro Hei" >0<=num<=255

Ord (CHR): Accept aASCIIorUnicodecharacter, which is a string of length one, returns the correspondingASCIIorUnicodevalues.

unichr (num) : Accept Unicode value, returning the corresponding Unicode characters.

Numerical Correlation Module--

decimal : Decimal floating-point arithmetic class Decimal .

Array : An efficient array of values.

Math /cmath : Standard c library mathematical operations functions, general mathematical operations in math modules, complex operations in cmath Span style= "Font-family:wenquanyi Micro Hei" > module.

operator : A function implementation of a mathematical operator.

Random : Multiple pseudo-random number generators.


Built-in functions and modules related to numbers in Python

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.