pow() in Python
- Difficulty Level : Basic
- Last Updated : 22 Sep, 2021
Python pow() function returns the power of the given numbers. This function computes x**y. This function first converts its arguments into float and then computes the power.
Syntax: pow(x,y)
Parameters :
- x : Number whose power has to be calculated.
- y : Value raised to compute power.
Return Value : Returns the value x**y in float.
Python pow() example
Example 1: Working of pow()
Python3
# Python code to demonstrate pow()# version 1("The value of 3**4 is : ", end="")# Returns 81(pow(3,4))Output:
The value of 3**4 is : 81.0Example 2: Python pow() with three argument
float pow(x,y,mod) function computes (x**y) % mod. This function first converts its arguments into float and then computes the power.
Syntax: float pow(x,y,mod)
Parameters :
- x : Number whose power has to be calculated.
- y : Value raised to compute power.
- mod : Value with which modulus has to be computed.
Return Value : Returns the value (x**y) % mod in float.
Python3
# Python code to demonstrate pow()# version 2("The value of (3**4) % 10 is : ", end="")# Returns 81%10# Returns 1(pow(3,4,10))Output:
The value of (3**4) % 10 is : 1Implementation Cases in pow() :
Python3
# Python code to discuss negative# and non-negative cases# positive x, positive y (x**y)("Positive x and positive y : ", end="")(pow(4,3))("Negative x and positive y : ", end="")# negative x, positive y (-x**y)(pow(-4,3))("Positive x and negative y : ", end="")# positive x, negative y (x**-y)(pow(4,-3))("Negative x and negative y : ", end="")# negative x, negative y (-x**-y)(pow(-4,-3))Output:
Positive x and positive y : 64 Negative x and positive y : -64 Positive x and negative y : 0.015625 Negative x and negative y : -0.015625This article is contributed by Manjeet Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
My Personal Notes arrow_drop_upRecommended ArticlesPage :Article Contributed By :Improved By :Article Tags :




