pow

Full name
pow
Library
Built-in
Syntax

pow(x, y[, z])

Description

The pow function returns the number included as the first argument, x, raised to the number included as the second argument, y. If a third argument, z, is added, the previous result is returned modulo z, an operation more efficient than

pow(x, y) % z

The arguments must have numeric types. If different types are mixed, the type coercion rules apply. For numbers of type integer, the result is also of type integer unless the second argument is negative, in which case all arguments are converted to real numbers and a real number is also returned. So pow(10, 2) returns the integer 100, but pow(10, -2) returns the real number 0.01.

If the second argument is negative, the third argument cannot be included. If the third argument is included in the function, the first two must be integers and the second cannot be negative.

Parameters
  • x: Calculation basis.
  • y: Exponent.
  • z: (Optional) number against which to calculate the modulo of pow(x, y).
Examples

We calculate 2 to the power of 3:

print(pow(2, 3))

Pow function. Example of use

 

If the third argument is added, the function returns the calculated power modulo z:

print(pow(2, 3, 3))

Pow function. Example of use

 

If x and y are integers and the latter is positive, the result is also an integer.

n = pow(10, 2)
print(n)
print(type(n))

Pow function. Example of use

If y is negative, the result is a real number:

n = pow(10, -2)
print(n)
print(type(n))

Pow function. Example of use

 

Submitted by admin on Sun, 01/20/2019 - 15:55