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 String split()
Python Program to Convert Kilometers to Miles
Python abs()
Python Program to Check if a Number is Odd or Even
Python String isnumeric()
Python Program to Parse a String to a Float or Int
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python locals()
Python Set pop()
Python Program to Find Sum of Natural Numbers Using Recursion
Python Data Types
Python Program to Find the Largest Among Three Numbers
Python float()
Python List copy()
Python bin()
Python Dictionary get()
Python for Loop
Python dir()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Operator Overloading
Python Dictionary keys()
Python Package
Python File I/O Operation
Python Program to Check If Two Strings are Anagram
Python Program to Display Fibonacci Sequence Using Recursion
Python @property decorator
Python sorted()
Python Dictionary popitem()
Python String isspace()
Python Program to Check Whether a String is Palindrome or Not
Python Program to Display the multiplication Table