MGU Computer Science Series — Programming with Python
Part I: Getting Started with Python
Values · Variables · Expressions · Tracing · Types
Chapter 3 of 30
3
MGU Computer Science Series  ·  Programming with Python  ·  Library Textbook Edition

Chapter 3:
Values, Variables,
and Expressions

The smallest building blocks of every Python program — how information is stored, named, computed, and traced

■ Part I of VII ■

■ 10 Sections  •  Chapter 3 of 30 ■

Prerequisite: Chapter 2 — Setting Up Python and Running Programs

Chapter Introduction and Learning Objectives

Every program works with information. Before a program can print a result, make a decision, repeat a task, or read a file, it needs to store and manipulate values. This chapter introduces the smallest building blocks of Python programs: values, variables, assignment, and expressions. By the end of this chapter, you will be able to read simple Python programs, trace how values change as each line runs, and write programs that compute and store results.

The concepts in this chapter are not complicated on their own — but they are fundamental. Variables, expressions, and assignment appear in every Python program you will ever read or write. Getting a precise, accurate understanding of how they work now will make everything that follows much easier.

Chapter Purpose

Chapter 2 taught you how to run Python programs. Chapter 3 teaches you what those programs are made of. Numbers, text, True/False values, names, calculations, and the rules Python uses to evaluate them — these are the vocabulary of the language. This chapter builds that vocabulary carefully before programs grow into conditionals, loops, and functions.

10Sections
12Objectives
22Key Terms
4Value Types

Learning Objectives

By the end of this chapter, you should be able to:

  1. 1Identify Python's four main value types: integers, floats, strings, and Booleans.
  2. 2Explain the difference between a value and a variable.
  3. 3Write and read assignment statements correctly, explaining what the = operator does.
  4. 4Name variables using Python's rules and the snake_case convention.
  5. 5Distinguish between integers and floats and explain when each is appropriate.
  6. 6Use all seven arithmetic operators and apply operator precedence correctly.
  7. 7Evaluate arithmetic expressions by hand, including expressions with parentheses.
  8. 8Perform string concatenation and explain why strings are not numbers.
  9. 9Describe Boolean values and explain what kinds of expressions produce them.
  10. 10Trace a short program line by line using a tracing table.
  11. 11Predict the output of simple programs involving variables and expressions.
  12. 12Identify and explain common errors: TypeError, NameError, and SyntaxError in the context of values and assignment.

Sections at a Glance

Sections 3.1 – 3.3
The Raw Material: Values, Variables, and Names
Types · Assignment · Naming Conventions · Memory

Values in Python

A value is a piece of information that a program works with. When you run a Python program, almost everything the program does involves values. The number 42 is a value. The text "hello" is a value. The result of multiplying 6 by 7 is a value.

Python recognizes many kinds of values. For now, the four most important ones are:

Type 1 — int
Integers
Whole numbers, positive or negative, with no decimal point. Examples: 0, 17, -5, 1000. Python integers can be arbitrarily large.
Type 2 — float
Floats
Numbers with a decimal point, representing fractional quantities. Examples: 3.14, 0.5, -2.7. Named for the floating-point representation used internally.
Type 3 — str
Strings
Text enclosed in quotation marks. Examples: "Python", 'hello', "42". A string is a sequence of characters — letters, digits, spaces, punctuation, or any combination.
Type 4 — bool
Booleans
The values True and False. Booleans represent yes/no, on/off, and other two-state conditions. They are the foundation of all decision-making in Python programs.

Each value belongs to a type. The type of a value tells Python what kind of information it is and what operations make sense for it. You can ask Python to tell you the type of any value using the built-in type() function:

type(42)
type(3.14)
type("hello")
type(True)

In the Python interactive shell, these produce:

<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>
On Quotation Marks

Python accepts both single quotes ('hello') and double quotes ("hello") for strings — either works. Throughout this textbook, double quotes are used by default. The only rule is that the opening and closing quote must match.

Values are not the same as variable names. The value 42 is the number forty-two. A variable named score might hold the value 42, but the name and the value are different things. Section 3.2 explains this distinction carefully.

Variables and Assignment

A variable is a name that refers to a value stored in the computer's memory. Variables let programs remember information, reuse it later, and change it when necessary.

In Python, you create a variable and give it a value using an assignment statement. The general form is:

variable_name = expression
The Assignment Operator

The = sign in Python is the assignment operator. It does not mean "equals" the way it does in mathematics. It means: evaluate the right side, then store the result under the name on the left. The direction of flow is always right-to-left.

Here are four assignment statements, one for each value type:

score = 95
price = 4.99
greeting = "Hello, world!"
is_valid = True

After these lines run, Python has four variables in memory. You can use any variable anywhere you would use its value directly. If score holds 95, then score + 5 produces 100.

Reassignment

A variable does not hold its value forever. You can assign a new value to it at any time:

score = 95
score = 80
score = score + 5

After the first line, score is 95. After the second line, score is 80. After the third line, score is 85 — because Python evaluates the right side first (80 + 5 = 85) and then stores 85 back into score.

Key Insight
The right side is always evaluated before assignment takes effect
  • Statementscore = score + 5
  • Step 1Python reads the right side: score + 5. The current value of score is 80, so this becomes 80 + 5.
  • Step 2Python evaluates 80 + 5, producing 85.
  • Step 3Python stores 85 into the variable named score. The old value 80 is gone.
  • Resultscore now holds 85. Python was not confused by score appearing on both sides because it always finishes evaluating the right side before performing the assignment.
Common Confusion

Beginners sometimes read score = score + 5 as a mathematical equation and think "that's impossible — score can't equal itself plus five." In Python, this is not an equation. It is a two-step instruction: compute score + 5, then store the result back into score. The old value is replaced.

Naming Variables Clearly

Python has rules for what variable names are allowed. Good programmers follow additional conventions that make code easier to read and maintain.

Python's Rules for Variable Names

RuleDetail
Start with a letter or underscoreThe first character must be a letter (a–z, A–Z) or an underscore (_). It cannot be a digit.
Letters, digits, underscores onlyAfter the first character, the name may contain letters, digits (0–9), and underscores. No spaces, hyphens, or other punctuation.
No Python keywordsReserved words such as if, for, while, def, True, False, None, and, or, not, return, class, and import cannot be used as variable names.
Names: Legal vs. Illegal
Examples at a glance
  • Legal ✓score   total_price   item_count   first_name   x   value1   _internal
  • Illegal ✗1score — starts with a digit
  • Illegal ✗total-price — hyphens are not allowed
  • Illegal ✗first name — spaces are not allowed
  • Illegal ✗if — reserved keyword; produces a SyntaxError

The snake_case Convention

Python's community convention is snake_case: all lowercase letters, with underscores between words. This is not enforced by the language, but it is expected by other Python programmers:

student_name = "Alex"
high_score = 100
average_temperature = 72.5

Avoid short, cryptic names like x, n, or tmp unless the meaning is obvious from context. Use names that describe what the variable holds, not how it is computed:

# Clear — the name tells you what it is
total_cost = price * quantity

# Unclear — the name tells you nothing
tc = p * q
Case Sensitivity

Python treats uppercase and lowercase letters as different characters. Score, score, and SCORE are three distinct variable names. By convention, ordinary variable names use all lowercase with underscores. Names in ALL_CAPS are reserved for constants — values meant never to change.

Taking time to name variables well is not a cosmetic concern. Descriptive names reduce errors, make programs easier to read, and help other programmers — including your future self — understand your code without needing to trace it line by line.

Sections 3.4 – 3.7
Numbers and Computation: Types, Operators, Expressions, and Precedence
int · float · Arithmetic · Evaluation · Order of Operations

Numeric Values: Integers and Floats

Python has two main numeric types: integers and floats. Knowing which type to use — and when Python will produce one or the other — prevents a category of errors that trips up many beginners.

Integers

Integers represent whole numbers without a fractional part. They can be positive, negative, or zero:

students = 30
temperature = -5
year = 2024
zero = 0

Python integers can be arbitrarily large — there is no upper limit for ordinary programs.

Floats

Floats represent numbers with a decimal point:

price = 19.99
weight = 0.75
pi = 3.14159
negative_float = -2.5
Floating-Point Imprecision

Try 0.1 + 0.2 in the Python shell. Python may display 0.30000000000000004. This is not a bug — it is a consequence of how all computers store decimal numbers in binary. For most programs at this stage, this will not cause problems. But it is worth knowing that 0.1 + 0.2 does not produce exactly 0.3 in Python.

Converting Between Types

Python provides functions to convert between integer and float types:

int(3.9)     # produces 3 — truncates (drops) the decimal, does NOT round
int(3.1)     # produces 3
float(7)     # produces 7.0

Division Always Produces a Float

Whenever you use the / operator, Python always produces a float result, even when both values are integers:

10 / 2       # produces 5.0, not 5
7 / 2        # produces 3.5

If you need a whole-number result, use integer division with //:

10 // 2      # produces 5
7 // 2       # produces 3  (the remainder 1 is discarded)

This distinction matters whenever your program counts things, indexes a list, or requires a whole-number result for further calculation.

Arithmetic Operators

Python provides seven arithmetic operators for working with numeric values.

OperatorMeaningExampleResult
+Addition5 + 38
-Subtraction10 - 46
*Multiplication6 * 742
/Division (always float)9 / 24.5
//Integer division (truncates)9 // 24
%Remainder (modulo)9 % 21
**Exponentiation2 ** 8256

The Remainder Operator

The % operator is less familiar than the others, but it is genuinely useful. 9 % 2 produces 1 because 9 = 4 × 2 + 1 — four goes into nine twice, with a remainder of one.

Use 1
Even or Odd
number % 2 == 0 is True for even numbers, False for odd ones. This is one of the most common uses of %.
Use 2
Last Digit
n % 10 extracts the last digit of any integer. 137 % 10 produces 7.
Use 3
Time Conversion
Converting 150 minutes: 150 // 60 gives 2 hours; 150 % 60 gives 30 remaining minutes.

Exponentiation

The ** operator raises the left value to the power of the right value:

2 ** 10     # produces 1024
3 ** 3      # produces 27
9 ** 0.5    # produces 3.0  (the square root of 9)

Integer and Float Mixing

When you combine an integer and a float in an arithmetic expression, Python produces a float result:

3 + 0.5     # produces 3.5
10 * 2.0    # produces 20.0

Expressions and Evaluation

An expression is a combination of values, variables, and operators that Python evaluates to produce a single result. Every expression has a value.

Here are examples of expressions — each one produces a value when Python evaluates it:

5 + 3
score * 2
price - discount
(length + width) * 2
temperature / 5 + 32

When Python encounters an expression, it evaluates it — it computes the result. The result can then be stored in a variable, printed, used in another expression, or returned from a function.

Expressions Involving Variables

Variables can appear anywhere a value can appear:

width = 10
height = 5
area = width * height
perimeter = 2 * (width + height)

Python reads the values stored in width and height, performs the calculations, and stores the results in area and perimeter.

Built-in Functions in Expressions

Some Python built-in functions return values that can be used inside expressions:

largest  = max(17, 42, 8)    # 42
smallest = min(17, 42, 8)    # 8
absolute = abs(-15)          # 15
rounded  = round(3.7)        # 4
Assignment Is Not an Expression

An assignment statement like score = 95 is not an expression — it does not produce a value. It performs an action: it stores a value into a name. This distinction matters more when you begin working with conditionals and function return values in later chapters.

Order of Operations

When an expression contains more than one operator, Python needs rules to decide which operation to perform first. These rules are called operator precedence.

Python follows the same order taught in mathematics:

PriorityOperator(s)Description
1 (highest)( )Parentheses — always evaluated first
2**Exponentiation
3- (unary)Negation of a single value, as in -5
4*   /   //   %Multiplication, division, integer division, remainder — evaluated left to right
5 (lowest)+   -Addition and subtraction — evaluated left to right
Precedence in Practice
Work these out before checking in Python
  • 2 + 3 * 4Multiplication first: 3 * 4 = 12, then 2 + 12 = 14. Result: 14, not 20.
  • (2 + 3) * 4Parentheses first: 2 + 3 = 5, then 5 * 4 = 20. Result: 20.
  • 10 - 4 / 2Division first: 4 / 2 = 2.0, then 10 - 2.0 = 8.0. Result: 8.0.
  • 2 ** 3 + 1Exponentiation first: 2 ** 3 = 8, then 8 + 1 = 9. Result: 9.
  • 20 - 5 - 3Equal precedence — left to right: (20 - 5) - 3 = 15 - 3 = 12. Result: 12, not 18.
When in Doubt, Use Parentheses

Even if you know the rules, parentheses that clarify your intent make code easier to read and less prone to errors.

Less clear: result = a + b * c - d / e

Clearer: result = a + (b * c) - (d / e)

Good programmers use parentheses not just when required, but whenever they make the expression's meaning clearer to a reader.

Sections 3.8 – 3.9
Beyond Numbers: Strings and Booleans
str · Text · Concatenation · bool · True · False · Comparisons

Strings as Text Values

A string is a sequence of characters enclosed in quotation marks. Strings represent text: names, messages, file paths, labels, input from users, and any information expressed as written characters rather than as numbers.

first_name = "Morgan"
city       = "Chicago"
message    = "Your score is excellent."
empty      = ""

The last example, "", is the empty string — a string with no characters. It is a valid string value.

Strings Are Not Numbers

Even if a string looks like a number, Python treats it as text:

x = "42"    # a string — the characters '4' and '2'
y = 42      # an integer — the number forty-two
TypeError: Can't Add a String and an Integer

Trying to add x + y (a string and an integer) produces a TypeError. Python does not automatically convert between types. The distinction between "42" and 42 is fundamental. Chapter 4 explains how to convert between them using int() and str().

String Concatenation

You can join two strings together using +. This is called concatenation:

first    = "Hello"
second   = "world"
combined = first + " " + second    # "Hello world"

Notice the space in the middle — Python does not add spaces automatically. You must include them explicitly in the string.

String Repetition

You can repeat a string using *:

line = "-" * 20    # "--------------------"
A Preview of Chapter 16

Strings have many capabilities beyond what this chapter covers: indexing individual characters, slicing portions, searching for substrings, and dozens of useful methods. Chapter 16 covers strings in depth. For now, the key ideas are: strings hold text, they are created with quotation marks, they are not numbers, and you can join them with +.

Booleans as True-or-False Values

A Boolean is a value that is either True or False. Booleans are named after the mathematician George Boole, who developed the algebra of logical reasoning.

In Python, the two Boolean values are written with capital first letters. They are not strings — do not write them in quotation marks:

True     # the Boolean value True
False    # the Boolean value False

"True"   # a string — the word "True" stored as text (different thing)

Booleans from Comparisons

Boolean values are often the result of comparing two values. Comparison expressions produce either True or False:

10 > 5        # True
10 < 5        # False
10 == 10      # True
10 == 5       # False
10 != 5       # True  (not equal)

You can store Boolean values in variables, just like any other type:

is_logged_in = True
has_error    = False
age_is_valid = age >= 18
A Preview of Chapters 5 and 6

Booleans are the language programs use to make decisions. Every if statement, every loop condition, and every logical check in a Python program ultimately depends on a Boolean value. Chapter 5 covers Boolean logic in full detail. For now, it is enough to know that Booleans exist, they can be stored in variables, and they are the result of comparisons.

A small preview: after temperature = 30 and is_hot = temperature > 25, the variable is_hot holds True. In Chapter 6, you will use values like this to control which parts of a program run.

Section 3.10
Tracing Variable Values
Tracing Tables · Step-by-Step Execution · Reading Programs Carefully

Tracing Variable Values

Tracing means following a program's execution step by step and recording the value of each variable at each point. Tracing is one of the most important skills in programming. When a program produces a wrong result, tracing reveals exactly where the values go wrong.

A tracing table is a systematic way to record how variables change as lines execute. The columns are the variable names. The rows represent lines of code. Each cell records the value of the variable after that line runs.

Worked Example 1 — Numeric Variables

Here is the program to trace:

x = 10
y = 3
z = x + y
x = x * 2
z = z + x

Build the table one line at a time. Write a dash for variables that do not exist yet.

LineCodexyzNote
1x = 1010——x created; y and z do not exist yet
2y = 3103—y created
3z = x + y1031310 + 3 = 13; stored in z
4x = x * 22031310 * 2 = 20; old value 10 is gone
5z = z + x20333x is now 20 (not 10): 13 + 20 = 33
The Critical Step

Line 4 changed x to 20. Line 5 used that updated value. If you had mistakenly carried x = 10 into Line 5, you would have computed 13 + 10 = 23 — wrong. This is exactly the kind of error that tracing catches before it becomes a bug.

After all five lines: x = 20, y = 3, z = 33.

Worked Example 2 — String Variables

first     = "Alex"
last      = "Kim"
full_name = first + " " + last
greeting  = "Hello, " + full_name + "!"
LineCodefirstlastfull_namegreeting
1first = "Alex""Alex"———
2last = "Kim""Alex""Kim"——
3full_name = first + " " + last"Alex""Kim""Alex Kim"—
4greeting = "Hello, " + full_name + "!""Alex""Kim""Alex Kim""Hello, Alex Kim!"
How to Trace Well

Go through the program one line at a time, in order. Evaluate the right side before performing any assignment. Update the table after each line. Do not skip ahead. Tracing is not guessing — it is systematic, deliberate reading. Programmers at every level use tracing to understand unfamiliar code and hunt down bugs.

Chapter Summary

Key Terms

assignment operator
The = symbol in Python. Evaluates the right side and stores the result in the variable named on the left. Not the same as mathematical equality.
assignment statement
A line of code that stores a value into a variable using the form variable_name = expression.
Boolean
A value that is either True or False. The Python type is bool. Used for all decision-making in programs.
concatenation
Joining two strings end to end using the + operator. Does not add spaces automatically.
evaluate
To compute the result of an expression. Python evaluates expressions before storing or using their results.
expression
A combination of values, variables, operators, and function calls that Python evaluates to produce a single result.
float
A numeric value with a decimal point. The Python type is float. Stored as floating-point binary internally, which can cause minor imprecision.
integer
A whole number without a decimal point. The Python type is int. Can be arbitrarily large in Python.
integer division
Division that discards the fractional part, performed with the // operator. Always produces an integer result.
keyword
A word reserved by Python for its own syntax, such as if, for, True, or def. Cannot be used as a variable name.
modulo
The % operator, which produces the remainder after integer division. 9 % 2 produces 1.
operator precedence
The rules determining which operators Python evaluates first in an expression containing multiple operators.
reassignment
Giving a variable a new value, replacing its previous value. The old value is no longer accessible through that name.
snake_case
Python's naming convention using lowercase letters with underscores between words: student_name, total_cost.
string
A text value enclosed in quotation marks. The Python type is str. A sequence of characters — not a number, even if it looks like one.
tracing
Following a program's execution step by step and recording each variable's value after each line runs. A fundamental debugging and understanding skill.
tracing table
A structured table with variables as columns and lines of code as rows, used to track how values change during execution.
type
The category of a value — int, float, str, or bool — which determines what operations are valid for that value.
value
A piece of information that a program works with: a number, a string, a Boolean, or another data item.
variable
A name that refers to a value stored in the computer's memory. Created by assignment; can be reassigned at any time.
PracticeExpression Practice

Compute the result of each expression by hand. Do not use Python yet — work it out first, then verify your answer in the shell.

  1. 3-E1. 8 + 3 * 2
  2. 3-E2. (8 + 3) * 2
  3. 3-E3. 15 / 4
  4. 3-E4. 15 // 4
  5. 3-E5. 15 % 4
  6. 3-E6. 2 ** 5
  7. 3-E7. 100 - 3 * 4 + 2
  8. 3-E8. (100 - 3) * (4 + 2)
  9. 3-E9. 17 % 5
  10. 3-E10. 5 ** 2 - 4 * 2 + 1
  11. 3-E11. 10 / 4 + 10 // 4
  12. 3-E12. "Hello" + " " + "Python"
  13. 3-E13. "*" * 8
  14. 3-E14. type(3.0)
  15. 3-E15. type(3)
PracticeVariable Tracing

For each program, build a complete tracing table. Record the value of each variable after each line executes. Write a dash if the variable does not yet exist.

  1. 3-T1.
    a = 5
    b = 12
    c = a + b
    a = a * 3
    c = c - a
  2. 3-T2.
    price = 8.50
    quantity = 4
    total = price * quantity
    discount = 5.00
    total = total - discount
  3. 3-T3.
    x = 100
    x = x // 3
    remainder = 100 % 3
    x = x + remainder
  4. 3-T4.
    first = "Kim"
    last = "Jordan"
    full = last + ", " + first
    label = "Name: " + full
  5. 3-T5.
    base = 2
    result = base ** 0
    result = result + base ** 1
    result = result + base ** 2
    result = result + base ** 3
    What is the final value of result? Can you see a pattern? What would the next step produce?
PracticePredict the Output

Predict exactly what Python will display. Then run each program to check your prediction.

  1. 3-P1.
    x = 7
    y = x * 3
    print(y)
  2. 3-P2.
    name = "Taylor"
    print("Hello, " + name + "!")
  3. 3-P3.
    a = 10
    b = 3
    print(a // b)
    print(a % b)
  4. 3-P4.
    total = 0
    total = total + 10
    total = total + 25
    total = total + 7
    print(total)
  5. 3-P5.
    x = 5
    x = x + x
    x = x * x
    print(x)
  6. 3-P6.
    n = 13
    print(n % 2)
    print(n // 2)
    print(n / 2)
  7. 3-P7.
    word = "Python"
    print(word + "!")
    print(word * 3)
  8. 3-P8.
    a = 4
    b = 7
    temp = a
    a = b
    b = temp
    print(a)
    print(b)
    What does this program do? Describe it in one sentence after predicting the output.
PracticeCommon Errors

Each code block contains one or more errors. Identify the error, explain what is wrong, and write a corrected version.

  1. 3-C1.
    1score = 95
  2. 3-C2.
    total cost = price * quantity
  3. 3-C3.
    x = 10
    y = 3
    print(x + "3")
  4. 3-C4.
    if = 42
  5. 3-C5.
    result = (5 + 3
  6. 3-C6.
    price = "9.99"
    total = price * 3
  7. 3-C7.
    True = 1
  8. 3-C8.
    balance = 100
    Balance = balance + 50
    print(balance)
    This program runs without an error, but it probably does not do what the programmer intended. What is the problem? What should the programmer write instead?
TasksShort Programming Tasks

For each task, write a complete Python program. Run it to verify it works correctly.

  1. 3-S1. Store your first name, last name, and age in three separate variables. Print each value on its own line.
  2. 3-S2. Compute the area and perimeter of a rectangle with width 14 and height 9. Store the results in variables named area and perimeter and print both with descriptive labels.
  3. 3-S3. A store sells notebooks for $3.75 each. Write a program that stores the price and a quantity of 12 in variables, computes the total cost, and prints the result.
  4. 3-S4. Write a program that stores any integer in a variable called number and then uses two separate print() statements to display the result of number % 2 and number // 2. (Do not use an if statement — just print the values.)
  5. 3-S5. Celsius converts to Fahrenheit with the formula F = C × 9/5 + 32. Write a program that stores a Celsius temperature of 25 in a variable and computes the Fahrenheit equivalent.
  6. 3-S6. Write a program that starts with balance = 500, then subtracts three expenses of 80, 45, and 120 one at a time (using three separate assignment statements), and prints the final balance.
  7. 3-S7. Using only string concatenation and the * repetition operator, build and print this label — store the stars and message in separate variables before combining them:
    ***** Welcome to Python *****
  8. 3-S8. A driver travels 240 miles in 4 hours. Write a program that computes the average speed in miles per hour, stores it in a variable named speed, then computes how long a 360-mile trip would take at that speed in a variable named trip_hours. Print both.
ReviewReview Questions

Answer each question in one to three sentences.

  1. 3-R1. What is a value? Give one example of each of Python's four main value types introduced in this chapter.
  2. 3-R2. What does the assignment operator = do in Python? How does it differ from the = sign in mathematics?
  3. 3-R3. Explain what happens when Python evaluates the statement x = x + 1. Why is this not a contradiction?
  4. 3-R4. Why is it important to give variables descriptive names? Give an example of a poor variable name and a better alternative for the same purpose.
  5. 3-R5. What is the difference between / and // in Python? Give an example where they produce different results.
  6. 3-R6. What does the % operator compute? Give one practical use for the remainder operator beyond the examples in this chapter.
  7. 3-R7. Why is the string "42" not the same as the integer 42? What would happen if you tried to add them together in Python?
  8. 3-R8. What is a Boolean? Give two examples of expressions that produce a Boolean value.
  9. 3-R9. What is a tracing table? Why is tracing a useful skill even for experienced programmers?
  10. 3-R10. What rule does Python follow when an expression contains multiple operators with the same precedence, such as 20 - 5 - 3? What result does this expression produce, and why?
Chapter 3 Checklist
Use this to confirm your understanding before moving to Chapter 4
Values and Types
  • I can identify Python's four main value types: int, float, str, and bool.
  • I can use type() to check what type a value belongs to.
  • I understand why the string "42" and the integer 42 are different.
  • I know what the empty string "" is and that it is a valid value.
Variables and Assignment
  • I can write an assignment statement and explain what = means in Python.
  • I can explain that the right side is evaluated before assignment takes effect.
  • I understand how x = x + 1 works and why it is not a contradiction.
  • I can name variables using Python's rules and the snake_case convention.
  • I know which words are reserved Python keywords and cannot be used as variable names.
Arithmetic and Expressions
  • I can use all seven arithmetic operators: +, -, *, /, //, %, **.
  • I know that / always produces a float, even with two integers.
  • I can explain what % computes and give a practical use for it.
  • I can apply operator precedence correctly and use parentheses to make order explicit.
  • I know that equal-precedence operators evaluate left to right.
Strings and Booleans
  • I can concatenate strings using + and repeat them with *.
  • I know that mixing strings and numbers with + causes a TypeError.
  • I know that True and False are Boolean values, not strings.
  • I know that comparison expressions produce Boolean values.
Tracing
  • I can build a tracing table for a short program involving variables and assignment.
  • I can predict the output of programs involving variables, arithmetic, and string operations.
  • I trace one line at a time and update values before moving to the next line.

Common Misconceptions

Misconception 1
"x = x + 1 is impossible — a number can't equal itself plus one."
In Python, = is not a mathematical equation — it is an assignment instruction. Python evaluates the right side first (the current value of x plus one), then stores the result back into x. The old value is replaced. This pattern is one of the most common in all of programming.
Misconception 2
""42" and 42 are the same thing — they're both forty-two."
They are completely different. "42" is a string containing the characters 4 and 2. 42 is an integer. You cannot add them together ("42" + 1 produces a TypeError), and Python will not automatically convert one to the other. Always be aware of which type you are working with.
Misconception 3
"Python's = and math's = mean the same thing."
In mathematics, x = 5 is a statement of equality — both sides are the same. In Python, x = 5 is an instruction to store the value 5 in the variable named x. Python's = always flows right-to-left and always represents an action, not a relationship.
Misconception 4
"10 / 2 produces 5."
In Python 3, 10 / 2 produces 5.0 — a float, not an integer. The / operator always returns a float. If you need the integer 5, use 10 // 2 instead.
Misconception 5
"Tracing is just for beginners — real programmers don't do it."
Experienced programmers trace unfamiliar code and debug tricky programs all the time — they just do it faster and sometimes mentally rather than on paper. Tracing is a genuine professional skill. The faster you build the habit now, the more natural it becomes as programs grow more complex.
Preview — Chapter 4
Input, Output, and Simple Programs

Chapter 3 introduced values, variables, and expressions — the raw material of Python programs. But so far, programs have not been interactive: they do not ask questions, respond to the user, or display formatted results.

Chapter 4 introduces how Python programs communicate with the person running them. You will learn the print() function in depth, including how to display text and numbers together cleanly. You will learn the input() function, which lets a program receive typed text from the user. You will learn type conversion — how to turn a string from input() into a number you can calculate with. And you will learn f-strings, Python's clean and readable way to build formatted output. By the end of Chapter 4, you will be able to write interactive programs that ask for information, perform calculations, and display results in a clear, readable format.

MGU Library Connection
  • Programming with Python — Appendix C: Python Syntax Quick Reference
  • Programming with Python — Appendix D: Common Python Error Messages
  • Companion resource: Variable Tracing Worksheet
  • Companion resource: Python Arithmetic Operators Reference
  • Companion resource: Debugging Checklist (errors in this chapter: TypeError, NameError, SyntaxError)
  • Previous chapter: Chapter 2 — Setting Up Python and Running Programs
  • Next chapter: Chapter 4 — Input, Output, and Simple Programs