Everything else is ready: study the parts, the key terms and the quiz below.
- Part 11What a variable is: assignment, names and values
- Part 22Names and objects: the namespace, id, two names for one object, and rebinding
- Part 33Multiple assignment, chained assignment, and swapping two variables
- Part 44Identifier rules, SyntaxError, the thirty five keywords and PEP 8 naming
- Part 55Recap and your challenge
Variables, Keywords and Identifiers
Bind names to objects, and name variables by Python's rules.
In this lesson5 parts
- 01What a variable is: assignment, names and values
- 02Names and objects: the namespace, id, two names for one object, and rebinding
- 03Multiple assignment, chained assignment, and swapping two variables
- 04Identifier rules, SyntaxError, the thirty five keywords and PEP 8 naming
- 05Recap and your challenge
Key terms
The words this lesson introduces, each in one line. The module’s glossary collects them all.
- variable · assignment
- a name given to a value · the instruction that gives it
- object · namespace · bind
- a value in memory with its type · the table of names · add a name with a reference to an object
- identifier · keyword
- the name of a variable · a word Python reserves (35 in 3.12)
Quiz 5 questions
Answer each one in your head, or on paper, before you check it. Getting one wrong here is how the lesson sticks.
- 01
After
total = 24.75andprevious_total = total, what istotal is previous_total? - 02
Then
total = 26.25. What isprevious_total? - 03
Is
item_2a valid identifier? Is2nd_item? - 04
What does
x = true(smallt) give? - 05
After
a, b = 1, 2anda, b = b, a, what areaandb?
Practice
Problems to solve in your own notebook. Each states the problem, not the steps: working out the steps is the exercise. Level A applies the lesson, B combines it with earlier ones, C stretches it.
The self-checking notebook for this lesson is Notebook 2 · Variables and Data Types.
Common mistakes
What you will see when it goes wrong, why it happens, and the fix.
Where it’s used
Where this lesson’s ideas turn up in real work.