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 Reverse a Number
Python Program to Capitalize the First Character of a String
Python Program to Convert Kilometers to Miles
Python Set add()
Python next()
Python Dictionary keys()
Python set()
Python delattr()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Program to Create a Countdown Timer
Python Sets
Python String replace()
Deep Learning with Python - Francois Chollet
Python String translate()
Python Deep Learning Cookbook - Indra den Bakker
Python Dictionary items()
Machine Learning with Python for everyone - Mark E.Fenner
Python Program to Check If a String Is a Number (Float)
Python Set intersection_update()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python ascii()
Python Program to Display the multiplication Table
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Variables, Constants and Literals
Python Program to Find Numbers Divisible by Another Number
Python Program Read a File Line by Line Into a List
Python Dictionary popitem()
Python String upper()
Python Program to Print the Fibonacci sequence
Python String maketrans()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Program to Find the Factorial of a Number