Variables — assignment and reassignment
x = 5 binds the name x to the int 5. Reassign x = 'hello' rebinds it to a string. Python is dynamically typed.
script.py
v3.1
Python output
click Run to execute
Click "Run" to execute the code on the left.
The output will appear here.
The output will appear here.
🧠 How it works
x = 5 creates an int object 5 in memory and binds the name x to it. x = 'hello' doesn't change the int — it rebinds x to a new str object. This is 'dynamic typing': the type lives on the OBJECT, not the NAME. Multiple assignment: a, b, c = 1, 2, 3 — Python packs the right side into a tuple, unpacks on the left. Swap: a, b = b, a — the right side is evaluated FIRST (as a tuple), then unpacked. No temp variable needed.
✏️ Try these changes
-
Change x = 5 to x = 5.5→ type becomes 'float' -
Change x = 'hello' to x = True→ type becomes 'bool' -
Add x = None after the list assignment→ type becomes 'NoneType' -
Change a, b, c = 1, 2, 3 to a, b, c = 'abc'→ a='a', b='b', c='c' — strings are iterable