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 Sort a Dictionary by Value
Python bytearray()
Python datetime
Python String isalpha()
Python String lower()
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Functions
Python isinstance()
Python Dictionary get()
Python List clear()
Python Errors and Built-in Exceptions
Python sorted()
Python Program to Get the Class Name of an Instance
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python List remove()
Python input()
Python sum()
Python Program to Find the Factors of a Number
Python list()
Python Program to Get the Last Element of the List
Python Statement, Indentation and Comments
Python Program to Measure the Elapsed Time in Python
Python String title()
Python Program to Print the Fibonacci sequence
Python max()
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Convert Bytes to a String
Python Set difference_update()
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Namespace and Scope
Python strptime()
Python Program Read a File Line by Line Into a List