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 toxy
pow(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 Artificial Intelligence Project for Beginners - Joshua Eckroth
Python String lower()
Python Exception Handling Using try, except and finally statement
Python compile()
Python String swapcase()
Python __import__()
Python pass statement
Python Anonymous / Lambda Function
Python round()
Python Program to Solve Quadratic Equation
Python Modules
Python repr()
Python Program to Reverse a Number
Python Program to Remove Duplicate Element From a List
Python Program to Sort Words in Alphabetic Order
Python type()
Python String strip()
Python String upper()
Python Program to Multiply Two Matrices
Python Program to Check if a Key is Already Present in a Dictionary
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python exec()
Python Dictionary items()
Python Dictionary get()
Python String translate()
Python dict()
Python ascii()
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python bytes()
Python List sort()
Python Functions
Python List copy()