Hi Programmers, In this guide, we are going to learn everything about the Python pow() function to return the value of x to the power of y ( i.e. xy).
It is a built-in function in Python that comes with Python by default. You can explore more about Python’s built-in functions by clicking here.
Headings of Contents
Python pow() function Introduction
Python pow() function is a built-in function which means you don’t require to download it using the Python pip command. pow() function in Python is used to find the value of b to the power of y.
Syntax
The syntax of the pow()
function in Python is:-
pow(number, power, modulus)
pow() Parameters
pow()
function in Python accepts three parameters number, power, and modulus.
- number:- A base value that is raised to a certain power.
- power:- A number that represents the exponent.
- modulus:- Optional, A number represents the number and it finds the remainder just like this number ^ power % modulus.
pow() Return Value
The pow() method returns:
- number ^ power, when two parameters provided
- number ^ power % modulus when three parameters are provided.
Python pow() function examples
Let’s understand the Python pow() function along with different-different examples so that you can understand it more.
Example: Using Python pow() function with two parameters
Using the Python pow()
function with two parameters number and power to return number ^ power.
x = 4
y = 3
result = pow(x, y)
print(result)
The output will be:- 64
Example: Using the pow() function with three parameters
Using the pow()
function with three parameters number, power, and modulus to be return number ^ power % modulus.
# Using Python pow function with third parameter.
x = 4
y = 3
z = 5
result = pow(x, y, z)
print(result)
The output will be:- 5
Conclusion
So, In this article, you have learned all about the pow() function to return the value of x to the power of y. This function is one of the best functions especially If you want to calculate the power of a number.
If you like this article, please share it and keep visiting for further python built-in functions tutorials.
Python built-in functions
For more information:- Click Here
Thanks for your valuable time … 🙏🙏❤️❤️