Variables
In Python a variable is a name bound to an object, not a box that holds a value. Assignment points a name at an object; it never copies the object.
Detailed Explanation
Most people learn variables from C or Java, where a variable is a labelled box of a fixed size and type. You declare int count;, the compiler reserves room for an integer, and count = 5 writes the bits 5 into that room. Python does not work this way, and almost every confusing Python bug traces back to that difference.
In Python, every value is an object living somewhere in memory. A name is a label you stick onto an object. count = 5 creates (or reuses) an integer object 5 and binds the label count to it. The name has no type and no fixed storage. The object has both.
Two consequences follow immediately.
First, assignment between names is aliasing, not copying. b = a does not duplicate anything. It adds a second label to the same object. If that object is mutable, such as a list or a dict, a change made through a is visible through b, because there is only one object. This is the single most common source of "my function modified my caller's data" surprises.
Second, rebinding a name is not the same as mutating an object. a = a + [4] builds a brand-new list and moves the label a onto it, leaving b on the old list. a.append(4) mutates the object both labels point at. The two lines look similar and behave very differently.
Names live in namespaces, which are essentially dictionaries mapping strings to objects. Module-level names are in globals(), function-local names are in the function's local scope, and attribute names live in an object's __dict__. A name comes into existence the moment you assign to it. There is no declaration step, which is why a typo like cuont = 5 is a silent new variable rather than a compile error.
Because names are untyped, you may rebind one to a completely different kind of object. That is legal and occasionally useful, but it makes code harder to read, so idiomatic Python keeps one meaning per name. Type hints such as count: int = 5 document your intent for tools like mypy; CPython itself stores the annotation and otherwise ignores it at runtime.
del a removes the binding, not the object. The object survives as long as some other name, container, or stack frame still references it. CPython frees it once the reference count drops to zero.
The practical rule: when you want an independent value, ask for a copy explicitly with list(x), x.copy(), or copy.deepcopy(x). When you want two names to track the same thing, plain assignment is exactly right. The cost of Python's model is that you must know which objects are mutable; the benefit is that passing large structures around is free, because nothing is copied.
Code Examples
# Assignment binds a name; it does not copy the object.
a = [1, 2, 3]
b = a # b is a second label on the SAME list
b.append(4)
print(a) # [1, 2, 3, 4] <- a sees the change
print(a is b) # True <- one object, two names
# Rebinding moves only one label.
a = a + [5] # builds a NEW list, rebinds a
print(a) # [1, 2, 3, 4, 5]
print(b) # [1, 2, 3, 4] <- b still on the old list
print(a is b) # False# A name has no type. The object does.
value = 42
print(type(value)) # <class 'int'>
value = "forty-two" # perfectly legal rebinding
print(type(value)) # <class 'str'>
# Annotations document intent; they are not enforced at runtime.
total: int = 0
total = "zero" # runs fine; mypy would flag it
print(total) # zero
# del unbinds the name, it does not destroy the object.
scores = {"ana": 9}
backup = scores
del scores
print(backup) # {'ana': 9} <- object still alive via backupCommon Gotchas
Aliasing is not copying
`settings = defaults` gives you one dict with two names. Mutating `settings` corrupts `defaults`. Use `dict(defaults)` for a shallow copy, or `copy.deepcopy` when the values are themselves containers.
`+=` means different things
on a list, `x += [1]` mutates in place and every alias sees it. On an int, tuple, or string, `x += 1` must rebind, because those objects are immutable. The same operator, two behaviours.
Assigning inside a function makes the name local
if a function assigns to `counter` anywhere in its body, Python treats `counter` as local for the whole function, and reading it before that assignment raises `UnboundLocalError`. Use `global` or `nonlocal` when you genuinely mean the outer name.
Typos create variables
because names spring into existence on assignment, a misspelled name is a new variable, not an error. Linters such as ruff or pyflakes catch the unused-name half of this.