English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python basic tutorial

Python flow control

Fonctions en Python

Types de données en Python

Python file operations

Python objects and classes

Python date and time

Advanced Python knowledge

Python reference manual

Python pow() usage and examples

Python built-in functions

The pow() function returns the power of the specified number.

The syntax of pow() is:

pow(x, y, z)

pow() parameters

The pow() function has three parameters:

  • x -a number, the base

  • y -a number, the exponent

  • z (optional) -a number used for modulus

Therefore,

  • pow(x, y) equals xy

  • pow(x, y, z) equals xy mod z

Example1: 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))    #25
# Negative x, negative y
print(pow(-2, -2))    #25

output result

4
4
0.25
0.25

Example2: has three parameters (x ** y) % z^y

x = 7
y = 2
z = 5
print(pow(x, y, z))    # 4

output result

4

Here,7of2to the power of equals49.49modulus of5equals4.

Python built-in functions