Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 pow() Function

Python3 pow() Function

Python3 Numbers Python3 Numbers


Description

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


Syntax

The syntax of the math module's pow() method is as follows:


import math

math.pow( x, y )

The built-in pow() method


pow(x, y[, z])

The function computes x raised to the power y; if z is present, it then takes the result modulo z, equivalent to pow(x,y) % z

**Note:** pow() is called directly as a built-in method; the built-in method treats arguments as integers, while the math module converts them to float.


Parameters


Return Value

Returns x

y

(x raised to the power y).


Example

The following shows examples 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 version and see the difference in output

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

)

)

Running the example above produces:


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 Numbers Python3 Numbers