CoursePython from Scratch to Intermediate · Module 1: Getting Started · part 10 of 75
Part 10 · Module 1: Getting Started

Lesson 3: Values, and the names that hold them

14 min read·14 Oct 2026
Module 1 · Lesson 3 · About 45 minutes · Needs: Lessons 1 and 2 (running a cell, print, reading an error's last line)

The situation

Amira wants the computer to print a card for one book. Before it can print anything, it has to hold the facts: which book, who wrote it, who has it, and since when. The book she picks is Frankenstein, the copy Jonah borrowed on Monday 14 September and still has. It is loan L04, and the course follows it further than any other.

This lesson gives you the two things every program is made of: values (the facts, such as the year 1818) and variables (names for those facts).

A real case, first

On 23 July 1983, Air Canada Flight 143, a Boeing 767, ran out of fuel in the middle of a flight. The crew glided the aircraft to a landing at a former air force base at Gimli, Manitoba, which is why the event is remembered as the "Gimli Glider". Nobody was killed. Canada's Board of Inquiry reported on it in 1985.

The cause was a number without its meaning. The amount of fuel on board was worked out using the wrong unit: pounds where kilograms were needed. What the number measured was not recorded with it, so nobody saw that the aircraft carried far less fuel than everyone believed.

Shelf records invite the same mistake. Is 14 a number of days, of books, or of pence? A value on its own does not say. This lesson gives every value a name that does.

What you will be able to do

  • Tell the four basic types of value apart and ask Python for a value's type.
  • Give a value a name with =, and change what a name points at.
  • Choose names Python accepts and other people can read.
  • Recognise the keywords you cannot use as names.
  • Assign several names on one line, and mark the shelf's rules as constants.

1. Values and their types at a glance (Essential)

Everything a program works with is a value: a title, a year, a fee. Python treats a year very differently from a title, so you need to know which kind you hold.

A VALUE ON ITS OWN A VALUE WITH A NAME 14 days? books? pence? LOAN_DAYS = 14 14 days, the loan period
A bare number leaves its meaning to guesswork (amber means uncertain); a name that says what it measures removes the guess (green means safe).

A bare value is what went wrong at Gimli. On the shelf, 14 could be the loan period, a count of books or a fee. The fix, built in this lesson, is a name that carries the meaning.

FOUR VALUES, FOUR TYPES "Frankenstein" str text 1818 int whole number 0.2 float decimal point True bool yes or no
Every value has a type: text is str, a whole number is int, a number with a decimal point is float, and True or False is bool (blue is a value your code holds).

Each value has a type: the kind of value it is. Text is a str (short for string, a string of characters). A whole number is an int (integer). A number with a decimal point is a float (floating-point number). True and False are a bool (Boolean, after the mathematician George Boole), the type for yes or no.

NO QUOTATION MARKS QUOTATION MARKS 1818 int: a number "1818" str: four characters
The same four digits are a number without quotation marks and text with them, and Python treats the two differently.

Quotation marks change the type. 1818 with no quotation marks is a number Python can count with. "1818" is text that happens to hold four digit characters. Module 2 shows how to turn one into the other.

python
print(type("Frankenstein"))
print(type(1818))
print(type("1818"))
print(type(0.2))
print(type(True))

Code walkthrough

  • type(...) is a tool built into Python: it reports the type of the value inside its brackets, and print shows the report. Module 2 Lesson 2 looks at it closely.
  • 0.2 is a float: a 20-pence fee held carelessly as pounds. This course always holds money as whole pence, an int; Module 2 Lesson 1 shows why.
  • True has a capital T and no quotation marks.

Output

text
<class 'str'>
<class 'int'>
<class 'str'>
<class 'float'>
<class 'bool'>

Read <class 'int'> as "this is an int": class is Python's word for a type (Module 9).

2. Variables as names for values (Essential)

Typing "Frankenstein" every time is slow and easy to get wrong. A variable lets you write the value once and use its name from then on.

title = "Frankenstein" the name make it point at the value ONE ASSIGNMENT
An assignment has three parts: the name on the left, the equals sign, and the value on the right that the name will point at.

The line title = "Frankenstein" is an assignment. The equals sign = means "make this name refer to this value": the name title on the left, the value "Frankenstein" on the right. The spaces around = are optional but usual.

A VARIABLE IS A LABEL title "Frankenstein" grey: the name blue: the value
A variable is a grey label with an arrow to a blue value: the name is not the value, it points at it, and this picture is used all course.

A variable is that name. Picture a label tied to a value: the name is not the value, it points at it. The course always draws a grey label with an arrow to a blue box.

JONAH'S LOAN, L04 title "Frankenstein" author "Mary Shelley" year 1818 loan_id "L04" member "Jonah" borrowed "Monday 14 September 2026"
Jonah's loan is six facts, and each one now has its own name, so the program can use any fact again by name.

Here is Jonah's loan in six variables, the Module 1 slice of the shared Booknook data.

python
title = "Frankenstein"
author = "Mary Shelley"
year = 1818
loan_id = "L04"
member = "Jonah"
borrowed = "Monday 14 September 2026"
print(title, "by", author, year)
print(loan_id, member, borrowed)

Code walkthrough

  • Six assignments. year holds a number, so it has no quotation marks; the other five hold text.
  • print takes several values separated by commas and shows them on one line, a space between each. "by" is typed straight in; for a name, print shows the value it points at.

Output

text
Frankenstein by Mary Shelley 1818
L04 Jonah Monday 14 September 2026

3. Assignment and reassignment (Essential)

Facts on the shelf change. Jonah borrowed the only copy, so the count on the shelf went from one to none. A program follows changes like that by pointing a name at a new value.

HOW PYTHON RUNS TITLE = "FRANKENSTEIN" 1. right side work out the value "Frankenstein" value ready 2. left side attach the name an instruction, done once, not a maths equation
Python runs an assignment right side first: it works out the value, then attaches the name, so = is an instruction and not a statement of equality.

Python runs an assignment in two steps: first it works out the value on the right, then it attaches the name on the left. So = is not "equals" in the maths sense; it is an instruction, done when the line runs. Testing equality uses == (Module 2).

COPIES_ON_SHELF = 1 THEN COPIES_ON_SHELF = 0 copies_on_shelf 1 copies_on_shelf 0 1 left behind on the shelf: 1 on the shelf: 0
Reassignment moves the label to a new value; the old value is not changed, only left behind (grey), and the same name now prints 0.

Reassignment means assigning a new value to a name that already exists. The label moves to the new value. The old value is not changed; the name just stops pointing at it.

python
copies_on_shelf = 1
print("on the shelf:", copies_on_shelf)
copies_on_shelf = 0   # Jonah borrows it on 14 September
print("on the shelf:", copies_on_shelf)

Code walkthrough

  • Line 1 points copies_on_shelf at 1. Line 3 moves the same name to 0; after the # is a comment, which Python ignores.
  • The two prints of one name give two answers, because a line in between moved it.

Output

text
on the shelf: 1
on the shelf: 0
AFTER HOLDER = MEMBER AFTER MEMBER = "PRIYA" member holder "Jonah" member holder "Priya" "Jonah" holder still points at Jonah
holder = member points a second label at the same value; moving member afterwards leaves holder where it was, because names point at values, not at other names.

holder = member makes holder point at whatever member points at now, "Jonah". Move member to "Priya" later and holder does not follow. Names point at values, never at other names.

python
member = "Jonah"
holder = member
member = "Priya"
print("holder:", holder)
print("member:", member)

Code walkthrough

  • Line 2 points holder at the value member holds, "Jonah". Line 3 moves only member.

Output

text
holder: Jonah
member: Priya
CELLS RUN IN THE ORDER YOU RUN THEM print(title) run first: NameError title = "Frankenstein" run first: name exists title = "Frankenstein" print(title) Frankenstein
A name exists only once the line that makes it has run: the same two cells fail in one order (red, an error) and work in the other (green).

A name exists only after the line that makes it has run. Colab cells can run in any order, so a cell using title fails if the cell making it has not run this session. When in doubt, choose Runtime, then Run all.

Break it: use a name that was never made

Swap two letters: the cell below asks for tilte. It fails on purpose. Run this and you will see:

text
title = "Frankenstein"
print(tilte)
text
Traceback (most recent call last):
  File "<string>", line 2, in <module>
NameError: name 'tilte' is not defined. Did you mean: 'title'?
READ THE LAST LINE FIRST print(tilte) NameError name 'tilte' is not defined what went wrong which name
The last line of the error names the kind of problem, a NameError, and the exact name Python did not know: the misspelt tilte.

Code walkthrough

  • Line 2 asks for tilte, a name no line has made. The error's last line says so.

A NameError means Python met a name it does not know. The last line names the problem and here guesses the fix; Colab may word or omit the guess.

4. Naming rules and conventions (Essential)

Python refuses some names outright, and accepts others that will confuse the next reader, often you a month later.

PYTHON ACCEPTS SYNTAXERROR due_day letters and _ book2 digit, not first _count may start with _ 2nd_copy starts with digit due day has a space due-day has a hyphen
A name may use letters, digits and underscores but must not start with a digit or hold a space or hyphen; break the rule and Python refuses with a SyntaxError (red).

The rules: a name may use letters, digits and the underscore _, must not start with a digit, and holds no spaces or hyphens. Break one and Python stops before running anything, with a SyntaxError: code it cannot read.

These three lines each fail on purpose. Run each in its own cell and you will see:

text
2nd_copy = 2
due day = 28
due-day = 28
text
  File "<string>", line 1
    2nd_copy = 2
    ^
SyntaxError: invalid decimal literal

  File "<string>", line 1
    due day = 28
        ^^^
SyntaxError: invalid syntax

  File "<string>", line 1
    due-day = 28
    ^^^^^^^
SyntaxError: cannot assign to expression here. Maybe you meant '==' instead of '='?

Code walkthrough

  • 2nd_copy starts with a digit. due day is two names side by side. due-day reads as due minus day, a sum you cannot assign to.
  • The ^ marks show where Python gave up reading. A SyntaxError has no "Traceback" line, because nothing ran.
TWO DIFFERENT NAMES title "Frankenstein" Title "Dracula" capital letters count
Python is case-sensitive: title and Title are two separate names, so one capital letter is enough to point at the wrong value or none.

Names are case-sensitive: title and Title are two separate names, so making Title and printing title gives a NameError.

THREE NAMES FOR THE SAME VALUE, 28 d means nothing DueDay not the convention due_day snake_case fee_per_day_pence = 20 the unit in the name: nobody reads it as pounds
PEP 8 asks for lower case words joined by underscores, snake_case, and a good name says what the value means and, where it matters, its unit.

Conventions are habits Python does not enforce, written down in PEP 8, the style guide for Python code (a PEP is a Python Enhancement Proposal). For variables it asks for lower case words joined by underscores, snake_case: due_day, not DueDay. A good name also says what the value means, and its unit: the Gimli lesson again.

python
due_day = 28                # shelf day: 14 September is day 14
fee_per_day_pence = 20
copies_on_shelf = 0
print("L04 due on day", due_day)
print("fee per day in pence:", fee_per_day_pence)

Code walkthrough

  • Until Module 7, dates are shelf days: 1 September is day 1, so L04, borrowed on day 14, is due on day 28.
  • fee_per_day_pence is long, but nobody will read it as pounds. Clear beats short.

Output

text
L04 due on day 28
fee per day in pence: 20

5. Keywords you cannot use as names (Essential)

A few words already have a job in Python's grammar. Use one as a name and Python refuses, so it pays to know the list.

KEYWORDS: NOT NAMES FREE TO USE AS NAMES class return for True genre returned author year 35 keywords in Python 3.12
Keywords such as class and return are part of Python's grammar and cannot be names; ordinary words such as genre are free.

These reserved words are keywords: if, for and while (Module 4), def and return (Module 6), class (Module 9), and True, False and None. Python prints the full list.

python
help("keywords")

Code walkthrough

  • help(...) is Python's built-in help; given "keywords", it lists them.

Output

text

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not                 

That is 35 words. Using one as a name fails at once. Run this and you will see:

text
class = "gothic"
text
  File "<string>", line 1
    class = "gothic"
          ^
SyntaxError: invalid syntax

Code walkthrough

  • A book's category, so class seems natural, but it is a keyword.

Use another word: the shared data says genre. It is also why Module 9's Library has return_book, not return. Python 3.12 also has four soft keywords, match, case, type and _, allowed as names but best avoided.

BEFORE AFTER TYPE = "GOTHIC" type the type tool type "gothic" the type tool unreachable by name type(1818) works type(1818) fails
type is not a keyword, so Python lets you reuse it, and then the name points at your text instead of the tool, which breaks every later type(...) call.

Break it: hide one of Python's own tools

print and type are not keywords, so nothing stops you reusing them. This breaks type for the whole session, so the course does not run it in your notebook. Run this and you will see:

text
type = "gothic"
print(type(1818))
text
Traceback (most recent call last):
  File "<string>", line 2, in <module>
TypeError: 'str' object is not callable

Code walkthrough

  • Line 1 points type at the text "gothic", so the tool can no longer be reached by that name. Line 2 finds text where it expects a tool.

"Not callable" means it cannot be used with brackets like a tool. If it happens in Colab, choose Runtime, then Restart session, which forgets every name.

6. Multiple assignment on one line (Recommended)

Some values belong together: a title, author and year. Python can name them in one line, which keeps related facts side by side.

PAIRED BY POSITION title "Frankenstein" author "Mary Shelley" year 1818
With several names and several values, Python pairs them by position: first name, first value, and so on along the line.

Put several names on the left of = and as many values on the right, separated by commas. Python pairs them by position. This is unpacking.

python
title, author, year = "Frankenstein", "Mary Shelley", 1818
print(title)
print(author)
print(year)

Code walkthrough

  • One line does three assignments; the prints show each name got the value in its position.

Output

text
Frankenstein
Mary Shelley
1818
THREE NAMES, TWO VALUES title "Frankenstein" author "Mary Shelley" year nothing left ValueError: not enough values to unpack
If the counts differ, a name is left with no value and Python stops with a ValueError instead of guessing.

The counts must match. Three names and two values is an error. Run this and you will see:

text
title, author, year = "Frankenstein", "Mary Shelley"
text
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: not enough values to unpack (expected 3, got 2)

Code walkthrough

  • year has no value to pair with.
BEFORE AFTER LEFT, RIGHT = RIGHT, LEFT left "Frankenstein" right "Dracula" left "Dracula" right "Frankenstein" both values are read before either name moves
A swap works in one line because Python reads both values on the right before it moves either name.

Amira has two books face out on the counter, Frankenstein left and Dracula right, and wants them swapped. Python reads the whole right side before attaching any name, so left, right = right, left swaps them.

python
left = "Frankenstein"
right = "Dracula"
left, right = right, left
print(left, "|", right)
late_days = fee_pence = 0
print(late_days, fee_pence)

Code walkthrough

  • Line 3 reads both values, then moves both names.
  • Line 5 is a chained assignment: both names point at the same value, 0.

Output

text
Dracula | Frankenstein
0 0

7. Constants by convention (Recommended)

The shelf has four rules that never change: 14 days, 20 pence a day, a 300-pence cap, 3 books. Naming each once, in a way that says "do not change me", beats writing 14 everywhere.

THE SHELF'S FOUR RULES LOAN_DAYS 14 days FEE_PER_DAY 20 pence FEE_CAP 300 pence MAX_BOOKS 3 books capitals: please never reassign
The shelf's four rules are constants: names in capitals that each say what they measure and that the program promises never to reassign.

A constant is a variable you promise never to reassign. PEP 8 writes constants in capitals with underscores. These four names are fixed for the whole course.

python
LOAN_DAYS = 14     # a loan lasts 14 days
FEE_PER_DAY = 20   # late fee, in pence, for each day after the due date
FEE_CAP = 300      # the most one loan can be charged, in pence
MAX_BOOKS = 3      # the most books one member may have out at once
print(LOAN_DAYS, FEE_PER_DAY, FEE_CAP, MAX_BOOKS)

Code walkthrough

  • Each comment gives the rule's meaning and unit; the capitals tell readers these are rules.

Output

text
14 20 300 3
THE CAPITALS ARE A CONVENTION LOAN_DAYS = 14 LOAN_DAYS = 7 no error LOAN_DAYS = 14 put back Python does not stop you; readers do
Python lets you reassign a constant without a word (amber: a value that may now be wrong), so the capitals protect the rule only if every reader respects them.

The capitals are a promise, not a lock:

python
LOAN_DAYS = 7
print("loan days now", LOAN_DAYS)
LOAN_DAYS = 14
print("loan days back to", LOAN_DAYS)

Code walkthrough

  • Line 1 breaks the promise with no error. Line 3 puts the rule back.

Output

text
loan days now 7
loan days back to 14

In production

Code is read far more often than it is written, so teams lean on these conventions. Most Python projects follow PEP 8 for names, and many run a linter, a tool that reads code and flags names such as DueDay. Shared rules sit once near the top of a file in capitals, so changing the loan period means changing one line. A type checker can also warn when a constant is reassigned, using type hints (Module 9).

What you added to the Booknook shelf

LOAN L04 RULES title "Frankenstein" author "Mary Shelley" year 1818 loan_id "L04" member "Jonah" borrowed "Monday 14 Sep..." LOAN_DAYS 14 FEE_PER_DAY 20 FEE_CAP 300 MAX_BOOKS 3 ten names so far, no files yet
After this lesson the shelf's facts and rules all have names; the module lab prints them as Amira's first shelf card.
  • Jonah's loan L04 held in six variables: title, author, year, loan_id, member, borrowed.
  • The shelf's four rules as constants: LOAN_DAYS, FEE_PER_DAY, FEE_CAP, MAX_BOOKS.
  • A habit: snake_case names that say what a value means, and its unit. The module lab turns these into Amira's first shelf card.

Check yourself

  1. What type is "20", and what type is 20?

"20" is a str, because of the quotation marks. 20 is an int.

  1. After a = "Kwame", then b = a, then a = "Lena", what does print(b) show?

Kwame. b was pointed at the value "Kwame"; moving a later does not move b.

  1. Which of these are legal names: book2, 2book, book_2, book-2, for?

book2 and book_2. 2book starts with a digit, book-2 has a hyphen, and for is a keyword.

Exercise

Priya has loan L24: The Adventures of Sherlock Holmes, by Arthur Conan Doyle, 1892, borrowed on Thursday 1 October 2026. Hold it in variables, with one multiple assignment for title, author and year, and print it. Compare your output with the one below, line for line.

python
loan_id = "L24"
member = "Priya"
borrowed = "Thursday 1 October 2026"
title, author, year = "The Adventures of Sherlock Holmes", "Arthur Conan Doyle", 1892
print(title, "by", author, year)
print(loan_id, member, borrowed)
print(type(year))

Code walkthrough

  • Three assignments, one unpacking, and a check that year is an int.

Output (yours should match exactly):

text
The Adventures of Sherlock Holmes by Arthur Conan Doyle 1892
L24 Priya Thursday 1 October 2026
<class 'int'>

Now write year as "1892" and rerun: the first line looks the same, the last says <class 'str'>. type shows what printing hides.

Key terms

TermMeaning
valueA piece of data, such as "Frankenstein" or 1818
typeThe kind of value: str, int, float or bool so far
variableA name that points at a value
assignmentA line with = that makes a name point at a value
reassignmentPointing an existing name at a new value
NameErrorThe error for a name Python does not know
SyntaxErrorThe error for code Python cannot read at all
snake_caseLower case words joined by underscores, the convention for variable names
keywordA word reserved by Python's grammar, such as class or return; not allowed as a name
unpackingNaming several values in one line: a, b = 1, 2
constantA variable in capitals that the program promises never to reassign
PEP 8The official style guide for Python code

Sources

  • Canada, Board of Inquiry into the Air Canada Boeing 767 C-GAUN incident at Gimli, Manitoba, on 23 July 1983, final report, 1985 (no stable official link known; cited by name).
  • Guido van Rossum, Barry Warsaw and Alyssa Coghlan, "PEP 8: Style Guide for Python Code", 2001, https://peps.python.org/pep-0008/ (sections "Naming Conventions" and "Constants").
  • Python Software Foundation, "The Python Language Reference, 3.12: Lexical analysis, Identifiers and keywords", 2023, https://docs.python.org/3.12/reference/lexical_analysis.html#identifiers
  • Python Software Foundation, "Built-in Functions: type and help", Python 3.12 documentation, 2023, https://docs.python.org/3.12/library/functions.html