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 Set copy()
Python abs()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Recursion
Python String rsplit()
Python Program to Calculate the Area of a Triangle
Python if...else Statement
Python Program to Display Calendar
Python next()
Python String index()
Python Program to Check if a Number is Odd or Even
Python Program to Illustrate Different Set Operations
Python bin()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Solve Quadratic Equation
Python String lower()
Python Program to Print Output Without a Newline
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Set update()
Python Set pop()
Python Tuple index()
Python Strings
Python round()
Python slice()
Python Package
Python Generators
Python hash()
Python Program to Merge Mails
Python Dictionary setdefault()
Python all()
Python pass statement
Python String format()