Python Programming · Foundations

Variables

Want it in plain words first? Jump to Eli explains — the same idea, no jargon.
On this page 9 sections
  1. In 30 seconds
  2. Why this matters
  3. The college version
  4. Eli explains
  5. Worked example
  6. Key takeaway
  7. Quick check
  8. Study tools
  9. Sources & references

In 30 seconds

In Python, a variable is usually best understood as a bound to an . Assignment, written with =, creates a or replaces an existing one. If place is first bound to one object and later assigned another value, the name has been rebound. A second name can still refer to the original object. This model explains why a variable is not simply a box that contains a value.

Why this matters

Reading Python accurately starts with tracing names. When a program assigns, reassigns, or copies a name into another name, ask which object each name refers to now. That habit helps predict output and later reason about shared references. It also prevents the mistaken assumption that changing one name must change every other name that once pointed at the same object.

The college version

Names are references, not containers

Python's execution model says that names refer to objects. A name is the spelling a program uses to reach an object; the object is the program's data. Assignment is one operation that creates that connection. In this lesson, variable is convenient everyday language for a name whose binding a program can use, but the more precise idea is name binding. For example, campus = "Riverside" binds the name campus to a string object. The equals sign is not a mathematical statement that two sides will remain identical. It performs an assignment. Python does not require a separate declaration before this statement; the binding is made when the statement executes. Identifier spelling belongs with Python Syntax, and the details of particular kinds of values belong in their own lessons.

Assignment can replace a binding

An can bind a name for the first time or rebind one that already has a connection. changes the name's connection; it does not reach backward and edit another name's connection. In direction = "north"; direction = "south"; print(direction), the output is south. The second assignment makes direction refer to the later object. In ordinary speech, it is acceptable to say the variable now has the later value, but a precise trace says the name's binding changed. The first object may or may not still be reachable through another name; that is a separate question. This is why tracing statements in execution order matters.

One object, more than one name

Python objects have an , type, and value. Identity lets a program ask whether two expressions refer to the same object. The is operator tests identity, unlike ==, an equality operation covered elsewhere. When two names refer to one object, they are aliases. Consider marker = object(); alias = marker; print(alias is marker). The result is True because both names refer to one object. If the program next executes marker = object(); print(alias is marker), the result is False. The later assignment gives marker a new binding, but it does not automatically rebind alias. The trace distinguishes aliasing from rebinding without depending on changes to a list or dictionary.

Keep two kinds of change separate

A variable-as-box picture can help as a first sketch, but it blurs a distinction. Rebinding changes which object a name refers to. Some objects can themselves change value, while others cannot; that behavior depends on the object and its type. Later collection lessons examine changes to mutable objects. Do not infer an object change merely because a name was assigned again. A practical tracing routine is to write every name on the left of an assignment and draw an arrow to the object reached on the right. If the right side is another name, copy that arrow's destination, not the letters of the name. On a later assignment to the left-hand name, erase and redraw only that arrow. This makes it visible why aliases can begin at one object and then diverge after one name is rebound. Predict the trace before execution, then run the code and compare output. This routine also avoids a misleading shortcut: seeing the same displayed value twice does not, by itself, prove that two names share an object. Identity is a separate property, and a program should use an identity check only when that is genuinely the question. Conversely, a shared reference is not evidence that two names will always remain aligned: a later assignment can redirect either name. Trace statements in order instead of guessing from variable names. That discipline scales from a three-line exercise to a larger program where a binding may be introduced far from the print statement you are interpreting. Accurate tracing is a practical skill, not merely vocabulary to memorize.

Eli, the EliExplains learning guide

Eli explains

The same idea, in plain words

Explain it like I’m 10

Think of an object as a particular library book and a name as a catalog card that points readers to that book. Writing alias = marker is like making a second catalog card that points to the same copy. If you later update the marker card so it points to a different book, the alias card does not magically move. It still points to the original copy. The names are not the books, and copying a name does not necessarily make a new object.

Picture it like this

Imagine two sticky notes, marker and alias, attached to the same sealed envelope. Replacing the marker note with one attached to another envelope leaves alias on the first envelope. The notes are names; the envelopes stand for objects.

Where the picture stops working

Python does not expose literal cards or envelopes, and object identity should not be treated as a street address. Some objects can change while their identity stays the same; the analogy is only for tracing each name's connection separately.

Worked example

Run this trace: first = "North"; second = first; first = "South"; print(first); print(second). Python prints South and then North. The first statement binds first to the object represented by "North". The second binds second to the same object currently reached by first. The third statement rebinds only first to the object represented by "South". It does not command Python to rewrite every binding made earlier, so second still refers to "North". This example traces bindings rather than arithmetic or a mutation of a collection.

Key takeaway

Python assignment binds names to objects, and assigning an already used name rebinds that name. Trace each name separately: aliases may start at the same object, then differ after one name is rebound.

Quick check

3 questions here, of 5 in this lesson’s practice set. Answers stay hidden until you check.

Question 1 of 3foundational

In Python's execution model, what does a name refer to?

Choose an answer, then check it.
Question 2 of 3intermediate

What does the second statement do in a = object(); b = a?

Choose an answer, then check it.
Question 3 of 3intermediate

After x = object(); y = x; x = object(), what is y is x?

Choose an answer, then check it.
Practice all 5

Keep learning

Ready to build on this? Continue to the next lesson.

Practice this lesson
Study tools & related lessonsYou’ll learn to · Common mistakes · Easily confused · Key vocabulary · Related

You’ll learn to

  • Define a Python name binding.
  • Distinguish an object from a name that refers to it.
  • Explain what reassignment, or rebinding, changes.
  • Trace two names that initially refer to the same object.
  • Use identity carefully to check whether two names refer to one object.

Common mistakes

  • Treating = as a permanent mathematical equality sign.

    Read it as an assignment that establishes or changes a binding.

  • Assuming b = a creates an independent object in every case.

    It makes b refer to the object currently reached by a.

  • Assuming rebinding one alias rebinds all aliases.

    Redraw only the assigned name's arrow.

  • Using is as a general replacement for equality.

    is asks whether two references have the same identity; equality is a different question.

Easily confused

Binding vs. Object

A binding is a name-to-object connection; an object is the data entity reached through it.

Rebinding vs. Object change

Rebinding changes a name's connection; it does not by itself establish that an object changed.

Alias vs. Copy

An alias is another name for the same object; a copy is a distinct object with separately determined identity.

Key vocabulary

name
An identifier that refers to an object in a Python program.
binding
The association between a name and an object.
assignment statement
A statement that binds or rebinds a target name.
rebinding
Replacing a name's existing association with another one.
object
Python's representation of data or a relation between data.
identity
The property that distinguishes one object from another during its lifetime.
alias
One of two or more names that refer to the same object.

Sources & references

  1. The Python Language Reference — Simple statements (assignment statements) — Python Software Foundation
  2. The Python Language Reference — Execution model (naming and binding) — Python Software Foundation
  3. The Python Language Reference — Data model — Python Software Foundation
  4. Python Documentation — Glossary (immutable, mutable, namespace, object) — Python Software Foundation

EliExplains lessons are original prose written from the open, credible references above. See Copyright & Licensing.

Researched 2026-08-19

Educational content only. It is not medical, legal or professional advice. Found an error? Tell us.