A function introduced .pow
Built-in functions in python pow () There are two parameters, x and y, and returns xy (x power of y) values, the following syntax:
pow(x, y[, z])
Parameter Description :
x - values are the expression (integer or floating point);
y - numeric expression (integer or floating point);
z - numeric expression (integer or floating point), does not set the default value of z;
Return Value : returns the value xy (x power of y); and if the z value is set, then the result of the modulo, the result is equivalent to pow (x, y)% z ;
Function uses two .pow
Case 1: pow function routine use
# ! Usr / bin / env Python # - * - Coding: UTF-8 _ * - "" " @author: Why grief @Blog (personal blog address): shuopython.com @WeChat Official the Account (micro-channel public number): Ape said Python @Github: www.github.com @file: python_pow.py @time: 2019/12/11 21:25 @Motto: short step a thousand miles, no small streams into a mighty torrent, wonderful life program It requires constant accumulation! "" " Print (POW (2,5)) # is equivalent to 2 * 2 * 2 * 2 * 2 = 32 Print (POW (2,3)) # is equivalent to 2 * 2 * 2 = . 8 Print (POW (2,3,5)) # is equivalent to 2% * 2 * 2 =. 8. 5%. 3. 5 = Print (2 * 2 * 2. 5%) # equivalent pow (2,3,5) = 3
Output:
32 8 3 3
Case 2: All parameters pow function must be a value type, not other types, otherwise an error TypeError
print(pow(2,'2'))
An exception:
Traceback (most recent call last): File "E:/Project/python_project/untitled10/123.py", line 18, in <module> print(pow(2,'2')) TypeError: unsupported operand type(s) for ** or pow(): 'int' and 'str'
Case 3: Ruoguo x, y has a float, the result is converted to floating point
print(pow(2,3.2)) print(pow(2,3.0))
Output:
9.18958683997628 8.0
you may also like:
1.python anonymous function lambda
2.python return logic expression is determined
4.python exception handling try except
Reproduced please specify: ape say Python » Python POW function