typestar

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

  1. Binds strings and numbers to names with plain =.
  2. Builds new values from old ones, then rebinds.
  3. Swaps two names in one line with tuple assignment.
  4. Grows a running total with the += shorthand.

Keywords and builtins used here

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.

Type this snippet

Step 1 of 6 in Variables & types, step 1 of 72 in Language basics.

Next →