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 Trim Whitespace From a String
Python String startswith()
Python help()
Python String islower()
Python Program to Return Multiple Values From a Function
Python Tuple
Python Set discard()
Python sum()
Python Program to Capitalize the First Character of a String
Python Program to Compute the Power of a Number
Python Program to Get File Creation and Modification Date
Python String encode()
Python Program to Print Hello world!
Python Program to Find HCF or GCD
Python abs()
Python String isdecimal()
Python Matrices and NumPy Arrays
Python hasattr()
Python Program to Find the Square Root
Python Program to Add Two Numbers
Python Program to Add Two Matrices
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Check If a String Is a Number (Float)
Python map()
Python Dictionary popitem()
Python Exception Handling Using try, except and finally statement
Python Program to Check if a Number is Positive, Negative or 0
Python locals()
Python File I/O Operation
Python len()
Python Program to Calculate the Area of a Triangle
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...