directory
- Introduction to Python poW functions
- The Python POW function is used
- Case 1: General use of poW functions
- Case 2: All poW parameters must be numeric types, not other types, otherwise TypeError will be reported
- Case 3: If x, y has a floating point number, the result is converted to a floating point number
- Guess you like it
Recommended courses for learning Basic Python: Python Learning Directory >> Getting Started with Python
Introduction to Python poW functions
The built-in pow function in Python takes two arguments, x and y, and returns xy (x ^ y). The syntax is as follows:
Parameter description: x -- numeric expression (integer or floating point number); Y - Numeric expression (integer or floating point); Z - A numeric expression (integer or floating-point) with no z value by default; Return value: returns the value of xy(x ^ y); If the z value is set, then the modulo of the result is equivalent to Pow (x,y) %z; ''' pow(x, y[, z])Copy the code
The Python POW function is used
Case 1: General use of poW functions
#! usr/bin/env python # ! Usr /bin/env python # -* -coding :utf-8 _*- "" www.codersrc.com @file :Python pow function. py @time :2021/04/19 07:37 @motto: A thousand miles without a small step, a river without a small stream, the wonderful life of the program needs to be accumulated with perseverance! "" "print (2, 5) (pow) # equivalent 2 * 2 * 2 * 2 * 2 = 32 print (pow) (2, 3) # equivalent 2 * 2 * 2 = 8 print,3,5 (2) (pow) # equivalent 2 * 2 * 5 = 2% 8% 5 = 3 Print (2*2*2) # print(2*2*2) = 1Copy the code
Case 2: All poW parameters must be numeric types, not other types, otherwise TypeError will be reported
#! usr/bin/env python # ! Usr /bin/env python # -* -coding :utf-8 _*- "" www.codersrc.com @file :Python pow function. py @time :2021/04/19 07:37 @motto: A thousand miles without a small step, a river without a small stream, the wonderful life of the program needs to be accumulated with perseverance! Print (pow(2,'2')) 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' '''Copy the code
Case 3: If x, y has a floating point number, the result is converted to a floating point number
#! usr/bin/env python # ! Usr /bin/env python # -* -coding :utf-8 _*- "" www.codersrc.com @file :Python pow function. py @time :2021/04/19 07:37 @motto: A thousand miles without a small step, a river without a small stream, the wonderful life of the program needs to be accumulated with perseverance! "" "print (pow,3.2) (2) print (pow,3.0) (2) ' 'output: 9.18958683997628 8.0' ' 'Copy the code
3.Guess you like
- The Python for loop
- The Python string
- The Python list
- The Python tuple tuple
- Python dictionary dict
- Python conditional derivations
- Python list derivations
- Python dictionary derivations
- Python function declarations and calls
- Python variable argument *argc/**kargcs
- Python anonymous function lambda
- Python return logic determines expressions
- Python string/list/tuple/dictionary conversions
- Python local and global variables
- The Python type function is different from the isinstance function
- Python is differs from ==
- Python mutable and immutable data types
- Shallow and deep copies of Python
Python poW functions
This article is published by the blog – Ape Say Programming Ape Say programming!