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 Function Arguments
Python Program to Differentiate Between del, remove, and pop on a List
Python iter()
Python timestamp to datetime and vice-versa
Python String strip()
Python Tuple index()
Python list()
Python Program to Add Two Matrices
Python Program to Sort a Dictionary by Value
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Iterators
Python Program to Make a Flattened List from Nested List
Python Set difference_update()
Python all()
Python Namespace and Scope
Python bin()
Python Program to Create Pyramid Patterns
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Type Conversion and Type Casting
Python Shallow Copy and Deep Copy
Python Set issuperset()
Python Program to Solve Quadratic Equation
Python Program to Get the File Name From the File Path
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python issubclass()
Python Keywords and Identifiers
Python Tuple count()
Python dir()
Python Program to Shuffle Deck of Cards
Python hasattr()
Python String replace()
Python Program to Copy a File