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 String isspace()
Python open()
Python Program to Find Sum of Natural Numbers Using Recursion
Python complex()
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python String rfind()
Python Program to Add Two Numbers
Python min()
Python Set pop()
Python String split()
Python Program to Count the Number of Digits Present In a Number
Python Program to Sort Words in Alphabetic Order
Python Program to Display Powers of 2 Using Anonymous Function
Python String endswith()
Python String expandtabs()
Python Set issuperset()
Python Sets
Python Program to Find the Size (Resolution) of a Image
Python Program to Calculate the Area of a Triangle
Python Dictionary keys()
Python Set update()
Python Program to Concatenate Two Lists
Python Object Oriented Programming
Python help()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python String rpartition()
Python Set issubset()
Python @property decorator
Python Program to Get the Full Path of the Current Working Directory
Python Program to Copy a File
Python Program to Merge Two Dictionaries
Python del Statement