Python offers to compute the power of a number and hence can make task of calculating power of a number easier. It has many-fold applications in day to day programming.
Naive Method to compute power :
The value of 3**4 is : 81
1. float pow(x,y) : This function computes x**y. This function first converts its arguments into float and then computes the power.
Declaration : float 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.
The value of 3**4 is : 81.0
2. float pow(x,y,mod) : This function computes (x**y) % mod. This function first converts its arguments into float and then computes the power.
Declaration : 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.
The value of (3**4) % 10 is : 1
Implementation Cases in pow() :
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.015625
This article is contributed by Manjeet Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.
- How to write an empty function in Python - pass statement?
- Operator Functions in Python | Set 2
- Time Functions in Python | Set-2 (Date Manipulations)
- Send mail from your Gmail account using Python
- Python – The new generation Language
- Print Single and Multiple variable in Python
- Increment and Decrement Operators in Python
- str() vs repr() in Python
- Swap two variables in one line in C/C++, Python, PHP and Java
- Generate all permutation of a set in Python
- Class or Static Variables in Python
- trunc() in Python
- Division Operators in Python
- Interesting facts about strings in Python | Set 1
- When to use yield instead of return in Python?