Python: Exponents & Modulo

By Hemanta Sundaray on 2022-01-02

Exponents

In Python, we use the notation ** to perform exponentiation.

# 2 squared
print(2 ** 2)
# 4

# 8 cubed
print(8 ** 3)
# 512

Modulo

The modulo operator is indicated by % and gives the remainder of a division calculation. If the number is divisible, then the result of the modulo operator will be 0.

print(12 % 2)
# 0

print(8 % 3)
# 2

Join the Newsletter