Skip to content

Python Power Operator

  • by

In Python power of a number can be calculated in two ways: using the exponent ** operator, or using the pow() function. The Python ** operator is used to raise a number in Python to the power of an exponent.

5 ** 2

Where the pow() function accepts three parameters: a base number, an exponent to which the base is raised, and a modulo operator.

pow(base, exponent, modulus)

Python Power Operator example code

A simple example code to get the value of 4 to the power of 3.

base = 4
exponent = 3

# Power ** Operator
print(base ** exponent)

# pow() Function
x = pow(base, exponent)
print(x)

Output:

Python Power Operator

Comment if you have any doubts or suggestions on this Python operator topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading