English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The pow() function returns the power of the specified number.
The syntax of pow() is:
pow(x, y, z)
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
# 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
x = 7 y = 2 z = 5 print(pow(x, y, z)) # 4
output result
4
Here,7of2to the power of equals49.49modulus of5equals4.