43 of 151 menu

The pow method of the math module

The pow method of the math module returns a number raised to a power. In the first parameter of the method, we specify the number we need, in the second parameter - to what power we want to raise it. Unlike the ** operator, the method always returns a real number.

Syntax

import math math.pow(number, degree)

Example

Let's square the number 3:

import math print(math.pow(3, 2))

Result of code execution:

9.0

Example

Now let's raise the number to a negative power:

import math print(math.pow(3, -2))

Result of code execution:

0.1111111111111111

Example

Let's use the pow method to cube a negative number:

import math print(math.pow(-3, 3))

Result of code execution:

-27.0

See also

  • method sqrt of module math,
    which returns the square root of a number
  • function round,
    which rounds off the number
byenru