Skip to main content
Practice

How to Calculate Squares in Python

The exponentiation operator ** returns the value of the number on the left raised to the power of the number on the right.

For example, a ** b returns a raised to the power of b.

Exponentiation Example
squared = 2 ** 3

print(squared) # 8

The exponentiation operator is useful for mathematical calculations, such as areas, volumes, and more.

Calculating the Area of a Square
side = 5 # Length of one side of the square

area_of_square = side ** 2 # Area of the square

print(area_of_square) # 25

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.