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 Dictionary values()
Python Functions
Python Directory and Files Management
Python Iterators
Python Program to Find HCF or GCD
Python String format()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Data Types
Python String upper()
Python String replace()
APIs in Node.js vs Python - A Comparison
Python round()
Python Global, Local and Nonlocal variables
Python String rindex()
Python Function Arguments
Python Program to Display Powers of 2 Using Anonymous Function
Python open()
Python Program to Extract Extension From the File Name
Python Program to Generate a Random Number
Python print()
Python String split()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Dictionary keys()
Python Program to Merge Mails
Python delattr()
Python Statement, Indentation and Comments
Python Program to Create a Long Multiline String
Python Dictionary get()
Python Custom Exceptions
Python eval()
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python String istitle()