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 globals()
Python help()
Python Program to Create a Long Multiline String
Python Program to Concatenate Two Lists
Python Program to Make a Flattened List from Nested List
Python String capitalize()
Python Tuple
Python String swapcase()
Python Program to Split a List Into Evenly Sized Chunks
Python Shallow Copy and Deep Copy
Python compile()
Python sleep()
Python bin()
Python Namespace and Scope
Python String partition()
Python Program to Display Fibonacci Sequence Using Recursion
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python iter()
Python Program to Display Powers of 2 Using Anonymous Function
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Count the Number of Occurrence of a Character in String
Python dir()
Python String rpartition()
Python Type Conversion and Type Casting
Python Data Structures and Algorithms - Benjamin Baka
Python time Module
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Program to Get the Class Name of an Instance
Python RegEx
Python Program to Transpose a Matrix
Python divmod()
Python String isnumeric()