Python3 pow() Function

Python3 数字Python3 Numbers


Description

pow()The method returns xy(the value of x raised to the power of y).


Syntax

The following is the syntax of the pow() method in the math module:

import math

math.pow( x, y )

Built-in pow() method

pow(x, y[, z])

The function calculates x raised to the power of y. If z is present, it then takes the modulus of the result, which is equivalent to pow(x, y) % z.

Note:pow() can be called directly through the built-in method, which treats parameters as integers, while the math module converts parameters to floats.


Parameters

  • x -- A numeric expression.
  • y -- A numeric expression.
  • z -- A numeric expression.

Return Value

Returns xy(the value of x raised to the power of y).

Example

The following demonstrates an example of using the pow() method:

Example

#!/usr/bin/python3
import math   # Import the math module

print ("math.pow(100, 2) : ", math.pow(100, 2))
# Use the built-in method to see the difference in output results
print ("pow(100, 2) : ", pow(100, 2))
print ("math.pow(100, -2) : ", math.pow(100, -2))
print ("math.pow(2, 4) : ", math.pow(2, 4))
print ("math.pow(3, 0) : ", math.pow(3, 0))

After running the above example, the output result is:

math.pow(100, 2) :  10000.0
pow(100, 2) :  10000
math.pow(100, -2) :  0.0001
math.pow(2, 4) :  16.0
math.pow(3, 0) :  1.0

Python3 数字Python3 Numbers

Other Extensions