Python Digital Function function

Source: Internet
Author: User

1. ABS (): Returns the absolute value of the given parameter. If the argument is a complex number, it returns the modulus of the complex number, that is, the square root of the sum of the real and imaginary parts of the complex number:

>>>abs ( -1)1>>>abs ( -56.78e-2)0.5678>>> (3+4j)5.0

2.coerce () (function in Python 2): Returns an element tuple containing two numeric values for the type conversion:

>>>coerce (2l,33) (2l,33l)>>>coerce (2l,33.0)(2.0,33.0)> >>coerce (2+3j,33.0)((2+3j), (33+0J))

3.divmod (): Combines the addition and subtraction operations to return a tuple containing quotient and remainder. The result of Divmod (N1,N2) is (N1//N2,N1%N2). Note: The function in Python2 supports complex numbers, but complex numbers are no longer supported in Python3.

>>>divmod (8.3,4) (2.0,0.3000000000000007)>>>divmod (2+3j,2) (1+0J), 3j)>>>divmod (2+3j,0+2j) ((1+0j), (2+1j))

4.pow (): Similar operator * *, can perform exponential operation, and can accept three parameters. The 1th and 2 parameters are exponential, and then the result is evaluated to the third parameter for the remainder operation. This feature is primarily used for cryptographic operations.

>>>pow (2,3)8>>>pow (2,3,5)3>>>pow (2+3j,2)(-5+12j)

5.round (): Used for rounding operations on floating-point numbers. Has an optional parameter that represents the number of decimal digits returned. If no optional argument returns the integer closest to the first parameter (still floating-point):

>>>round (2.45678)2.0>>>round ( -2.45678,1)-2.5>>>round (2.45678,2 )2.46

Python Digital Function function

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.