First steps
Variables and types
Goal: Store values in variables and recognise basic types · 8 min
A variable is a name that refers to a value. = is the assignment operator: age = 17 stores 17 under the name age. It is not a mathematical equation — x = x + 1 means "compute x + 1, then store it in x".
Basic types:
int— whole numbers: 7, -3float— decimal numbers: 3.14 (Python uses a dot)str— text: "Berlin"bool— truth values: True, False
type(value) tells you the type. Converting: int("42") → 42, str(42) → "42", float("2.5") → 2.5. Names may contain letters, digits and underscores, must not start with a digit and are case-sensitive.
Worked example: Reassigning
x = 5stores 5.x = x * 2computes 10 and stores it in x.print(x)prints 10.
x = 5
x = x * 2
print(x)Output:
10