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

  1. The Python for loop
  2. The Python string
  3. The Python list
  4. The Python tuple tuple
  5. Python dictionary dict
  6. Python conditional derivations
  7. Python list derivations
  8. Python dictionary derivations
  9. Python function declarations and calls
  10. Python variable argument *argc/**kargcs
  11. Python anonymous function lambda
  12. Python return logic determines expressions
  13. Python string/list/tuple/dictionary conversions
  14. Python local and global variables
  15. The Python type function is different from the isinstance function
  16. Python is differs from ==
  17. Python mutable and immutable data types
  18. Shallow and deep copies of Python

Python poW functions

This article is published by the blog – Ape Say Programming Ape Say programming!