Python pow() function

Python pow() Function

Description

The pow() function returns x raised to the power of y. It is equivalent to xy. This function has an optional third parameter, mod. If mod is given, the function returns (xy) % mod.

Syntax

pow(x, y, mod = 1)

Parameters

  • x – Numeric operand, used as the base
  • y – Numeric operand, used as the exponent

  • mod – Numeric operand, used as the denominator in the modulo operation

Example

x = 2
y = 3
power = pow(x,y)
print ("x: ",x,"y:",y, "pow(x,y): ", power)

x = 49
y = 0.5
power = pow(x, y)
print ("x: ",x,"pow(x,y): ", power)

x = 10
y=2
z = 6
power = pow(x,y,z)
print ("x: ",x,"y:",y, "z:",z, "pow(x,y,z): ", power)

It will produce the following output

x: 2 y: 3 pow(x,y): 8
x: 49 pow(x,y): 7.0
x: 10 y: 2 z: 6 pow(x,y,z): 4

Leave a Reply

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