Python pow() Function

Python 数字Python Numbers


Description

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


Syntax

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

import math

math.pow( x, y )

Built-in pow() method

pow(x, y[, z])

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

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


Parameters

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

Return Value

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

Example

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

Example

#!/usr/bin/python # -*- coding: UTF-8 -*- import math # Import the math module print "math.pow(100, 2) : ", math.pow(100, 2) # Use the built-in 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

Python 数字Python Numbers

Other Extensions