Python built-in functions (49) -- pow, python built-in 49pow

Source: Internet
Author: User

Python built-in functions (49) -- pow, python built-in 49pow

English document:

pow( X, Y[, Z])
Return XTo the power Y; If ZIs present, return XTo the power Y, Modulo Z(Computed more efficiently pow(x, y) % z). The two-argument form pow(x, y)Is equivalent to using the power operator: x**y.
The arguments must have numeric types. With mixed operand types, the coercion rules for binary arithmetic operators apply. intOperands, the result has the same type as the operands (after coercion) unless the second argument is negative; in that case, all arguments are converted to float and a float result is delivered. for example, 10**2Returns 100, 10**-2Returns 0.01. If the second argument is negative, the third argument must be omitted. If ZIs present, XAnd YMust be of integer types, and YMust be non-negative.

 

Note:
1. the function has two required parameters x, y, and an optional parameter z. The result returns the y Power Multiplication (equivalent to x ** y) of x. If the optional parameter z has an input value, returns the power multiplication and then modulo z (equivalent to pow (x, y) % z ).
>>> pow(2,3)8>>> 2**38>>> pow(2,3,5)3>>> pow(2,3)%53

2. All parameters must be numerical.

>>> pow('2',3)Traceback (most recent call last):  File "<pyshell#13>", line 1, in <module>    pow('2',3)TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'

3. If one of x and y is a floating point number, the result is converted to a floating point number.

>>> pow(2,0.1)1.0717734625362931

4. if both x and y are integers, the result is also an integer unless y is a negative number. If y is a negative number, the result returns a floating point number. The floating point number cannot be modulo, values cannot be input for all optional z parameters.

>>> pow(10,2)100>>> pow(10,-2)0.01>>> pow(10,-2,3)Traceback (most recent call last):  File "<pyshell#16>", line 1, in <module>    pow(10,-2,3)ValueError: pow() 2nd argument cannot be negative when 3rd argument specified

5. If the optional parameter z is passed in, x and y must be integers and y cannot be negative.

>>> pow(2,3,5)3>>> pow(10,0.1,3)Traceback (most recent call last):  File "<pyshell#17>", line 1, in <module>    pow(10,0.1,3)TypeError: pow() 3rd argument not allowed unless all arguments are integers>>> pow(10,-2,3)Traceback (most recent call last):  File "<pyshell#16>", line 1, in <module>    pow(10,-2,3)ValueError: pow() 2nd argument cannot be negative when 3rd argument specified

 

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.