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 ** operator is useful in math for calculating powers, such as areas and volumes.
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
Quiz
0 / 1
Using the Power Operator in Python
Run the following code to calculate the area of a square. The expected output is 49.
side = 7area_of_square = side 2print(area_of_square)Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help
Code Editor
Run
Generate
Execution Result