Variables and assignment in Python
How values get names: the very first move in any language.
name = "Ada"
year = 1815
languages = 2
greeting = "Hello, " + name
age_now = 2026 - year
first, last = "Ada", "Lovelace"
first, last = last, first
total = 0
total += languages
total += age_now
print(greeting, total)
How it works
- Binds strings and numbers to names with plain
=. - Builds new values from old ones, then rebinds.
- Swaps two names in one line with tuple assignment.
- Grows a running total with the
+=shorthand.
Keywords and builtins used here
print
The run, in numbers
- Lines
- 14
- Characters to type
- 218
- Tokens
- 58
- Three-star pace
- 80 tpm
At the three-star pace of 80 tokens a minute, this run takes about 44 seconds.
Step 1 of 6 in Variables & types, step 1 of 72 in Language basics.