Python1age = 302age = age + 13price = 2.54ok = True5word = "2" + "2"6num = int("2") + 27bad = "2" + 2TypeError
Code card: the program; the highlighted line is the one runningMemory boxes: one per name, showing its current valueType tags: int, float, bool or strPython: runs each line and raises an error when it cannotEach step highlights one line of the program. A value token hops along the step's arrow: from the line into a name's memory box when = stores a value, and from the box back to the line when the line reads it. The box's name, value and type tag crossfade in when the token lands. Line 5 joins two strings into '22'; line 6 converts "2" with int() first, so + adds and gives 4; line 7 mixes a str and an int, so Python raises a TypeError and stores nothing. The drawing gives each name one box. Strictly, a Python name refers to an object in memory, and reassignment makes the name refer to a new object (31) instead of the old one (30).

Store and read

  1. Line 1 runs. Python makes the whole number 30 in memory and ties the name age to it. Read = as "store": it stores whatever is on its right.

Four types

Mixing types

Try it in the Python prompt

;; step 1/8 · line 1: age = 30
>>> age = 30
>>> age
30
>>> type(age)
<class 'int'>

The drawing gives each name one box. Strictly, a Python name refers to an object in memory, and reassignment makes the name refer to a new object (31) instead of the old one (30). An error that nothing handles stops the program, so in a script no line after line 7 would run.