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

pythonimport math

math.pow(number, degree)

Example

Let's square the number 3:

pythonimport math

print(math.pow(3, 2))

Result of code execution:

python9.0

Example

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

pythonimport math

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

Result of code execution:

python0.1111111111111111

Example

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

pythonimport math

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

Result of code execution:

python-27.0

See also

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