Lecture
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
Lessons in this chapter · Numeric Data Types and Operators
- 1. Working with Numbers in Python
- 2. Arithmetic Operations in Python
- 3. Integer Division Operator //
- 4. Remainder Operator %
- 5. How to Calculate Squares in Python
- 6. Multiple-choice quiz
- 7. Determining Operator Precedence
- 8. TypeError Caused by Operations Between Different Data Types
- 9. What Do `+=`, `-=` Mean?
- 10. Python Integer Division Operator Coding Quiz
- 11. Multiple-choice quiz
- 12. Fill-in-the-blank quiz
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