Table of Contents
The pow() function returns the power of a number.
The syntax of pow() is:
pow(x, y, z)
1. pow() Parameters
The pow() function takes three parameters:
- x – a number, the base
- y – a number, the exponent
- z (optional) – a number, used for modulus
Hence,
pow(x, y)is equal toxypow(x, y, z)is equal toxy % z
2. Example 1: Python pow()
# positive x, positive y (x**y) print(pow(2, 2)) # 4 # negative x, positive y print(pow(-2, 2)) # 4 # positive x, negative y print(pow(2, -2)) # 0.25 # negative x, negative y print(pow(-2, -2)) # 0.25
Output
4 4 0.25 0.25
3. Example 2: pow() with three arguments (x**y) % z
x = 7 y = 2 z = 5 print(pow(x, y, z)) # 4
Output
4
Here, 7 powered by 2 equals 49. Then, 49 modulus 5 equals 4.
Related posts:
Python Program to Access Index of a List Using for Loop
Python type()
Python List clear()
Python print()
Python Program to Print Colored Text to the Terminal
Python Program to Display Powers of 2 Using Anonymous Function
Python Global, Local and Nonlocal variables
Python Set symmetric_difference_update()
Python min()
Python Set intersection()
Python String isspace()
Python strptime()
Python Program to Convert String to Datetime
Python Program to Differentiate Between type() and isinstance()
Python format()
Python String join()
Python hash()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python String isdigit()
Python String startswith()
Python Program to Convert Kilometers to Miles
Python String isnumeric()
Python Program to Find Factorial of Number Using Recursion
Python List remove()
Python Program to Get the Last Element of the List
Python Dictionary get()
Python Dictionary popitem()
Python String format()
Python Modules
Python all()
Python __import__()
Python Strings