Why does `x = x + 1` work if `=` doesn't mean equals — and what does Python do with the old object in memory?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
A circle has pi = 3.14 and radius = 10, both given below. Compute the circle's
area — pi times the radius squared — and assign it to area. Remember that Python
applies exponentiation before multiplication.
Every value as a typed object
State that each value is an object whose type fixes the valid operations, and draw the memory diagram for pi = 3.14, radius = 2.2, area = pi * radius**2.
Rebinding in radius = radius + 1
Trace the line with radius bound to 2.2: the right side evaluates to 3.2, a new object is created, and the name moves while 2.2 stays unmodified.
A name bound to a type itself
Work through var = type(5 * 4) step by step, recording 5 * 4 as 20, then type(20) as int, the object finally bound to var.