Python pow() Built in Function

The pow() function is used to calculate the power of a number by raising the first argument to the second argument. The syntax of the pow() function is:

pow(x, y, z)

The x and y parameters are required and represent the base and the exponent respectively. The z parameter is optional and represents the modulus. If z is present, it returns x to the power of y, modulus z. Otherwise, it returns x to the power of y.

Here are some examples of using the pow() function in Python:

To calculate 4 to the power of 3 (same as 4 * 4 * 4):

print(pow(4, 3)) # prints 64

To calculate 2 to the power of 10 (same as 2 * 2 * … * 2):

print(pow(2, 10)) # prints 1024

To calculate 5 to the power of 2, modulus 7 (same as (5 * 5) % 7):

print(pow(5, 2, 7)) # prints 4 

If you have any questions about this code, you can drop a line in comment.

Comments

Popular posts from this blog

Python chr() Built in Function

Stock Market Predictions with LSTM in Python

Collections In Python

Python Count Occurrence Of Elements

Python One Liner Functions