What a variable really is
In Python a variable is not a container; it is a reference (a label) bound to an object. When you write age = 30, Python creates an int object 30 and binds the name age to it. The same object can have multiple names:
a = [1, 2, 3]
b = a # b points to the SAME list
a.append(4)
print(b) # [1, 2, 3, 4]
This matters for mutable objects like lists and dicts: two names can share one underlying value.
The core built-in types
| Type | Example | Mutable | Use |
|---|---|---|---|
int | 10 | no | whole numbers |
float | 1.5 | no | decimals |
str | "hi" | no | text |
bool | True | no | true/false |
list | [1, 2] | yes | ordered sequence |
tuple | (1, 2) | no | immutable sequence |
dict | {"a": 1} | yes | key/value pairs |
set | {1, 2} | yes | unique values |
Pick tuple over list when the data should not change; pick dict when you need labelled lookup.
Type coercion and conversion
Python converts types in two ways. Implicit conversion happens automatically in expressions, e.g. 1 + 2.5 becomes 3.5 (the int is promoted to float). Explicit conversion uses constructors: int(), float(), str(), list(), dict().
Mixed-type comparisons like 1 == "1" are False because the types differ. Always convert before comparing when the source may be a string.