Python pow()

In this post, we will see about Python pow() function.
Python pow(x,y) returns x to power of y.


Syntax


Return

It returns

  • x to the power of y
  • If z is provided then pow function returns x to the power of y, module z which is efficient than pow(x,y)%z

pow(x,y) is equivalent to x**y

Arguments must be of numeric type. If x and y both are integer, result will be int. If y is negative, then result will be float.


Example

Let’s see a simple example:

# in case of two arguments x,y print("2 to the power of 4:",pow(2,4)) print("3 to the power of 9:",pow(3,9)) print("16 to the power of 0.5:",pow(16,0.5)) print("16 to the power of -2:",pow(16,-2)) # in case of three arguments x,y,z print("2 to the power of 4 module 3:",pow(2,4,3)) print("3 to the power of 9 module 6:",pow(3,9,6))

Output:

2 to the power of 4: 16
3 to the power of 9: 19683
16 to the power of 0.5: 4.0
16 to the power of -2: 0.00390625
2 to the power of 4 module 3: 1
3 to the power of 9 module 6: 3

That’s all about pow function in python.

Leave a Reply

Your email address will not be published. Required fields are marked *