Review
From the Python Programming Notes curriculum
TL;DR
This review helps you recap core Python concepts like variables, data types, control flow, functions, and basic data structures. We'll refresh your understanding of how these pieces fit together to write simple programs. Mastering these fundamentals is key to building more complex and effective code.
1. The Mental Model
Think of Python as your helpful assistant. You give it clear instructions (your code) using its specific language. It follows these instructions step-by-step to achieve a task, managing information, making decisions, and repeating actions as you direct.
2. The Core Material
Variables and Data Types

Photo by Markus Spiske on Pexels
Variables are like named containers for storing data. Python automatically figures out the type of data you're storing.
# Variables and basic data types
age = 30 # int (integer)
name = "Alice" # str (string)
height = 1.75 # float (floating-point number)
is_student = True # bool (boolean - True/False)
print(f"{name} is {age} years old and is {height} meters tall. Is she a student? {is_student}")
Operators
These symbols perform operations on values. Arithmetic (+, -, *, /, %), comparison (==, !=, <, >, <=, >=), and logical (and, or, not) are common.
# Arithmetic
result = 10 + 5 * 2 # Order of operations applies
# Comparison
is_equal = (age == 30)
# Logical
can_vote = (age >= 18 and is_student == False)
Control Flow (If/Else, Loops)

Photo by Steve A Johnson on Pexels
Control flow dictates the order in which instructions are executed.
Conditional Statements (if, elif, else)
These allow your program to make decisions.
# If/Else example
temperature = 25
if temperature > 30:
print("It's hot!")
elif temperature > 20:
print("It's warm.")
else:
print("It's cool.")
Loops (for, while)
Loops allow you to repeat actions. for loops are great for iterating over sequences; while loops repeat as long as a condition is true.
# For loop
for i in range(3): # Iterates 0, 1, 2
print(f"Loop count: {i}")
# While loop
count = 0
while count < 2:
print(f"While count: {count}")
count += 1 # Important to change the condition, or it's an infinite loop!
Functions
Functions are reusable blocks of code that perform a specific task. They help organize your code and avoid repetition.
# Function definition
def greet(person_name):
"""This function greets the person passed in as an argument."""
return f"Hello, {person_name}!"
# Calling the function
message = greet("Bob")
print(message)
Data Structures (Lists, Dictionaries)

Photo by freestocks.org on Pexels
These help you store and organize collections of data.
Lists
Ordered, mutable (changeable) collections of items.
# List example
fruits = ["apple", "banana", "cherry"]
fruits.append("date") # Add an item
print(fruits[1]) # Access an item (index starts at 0)
Dictionaries
Unordered, mutable collections of key-value pairs. Each key must be unique.
# Dictionary example
person = {
"name": "Charlie",
"age": 40,
"city": "New York"
}
print(person["age"]) # Access value by key
person["city"] = "London" # Modify a value
Here's a quick look at how these elements fit together:
graph TD
A["Start Program"] --> B{"Define Variables"};
B --> C{"Use Operators (e.g., Arithmetic)"};
C --> D{"Conditional Logic (if/elif/else)"};
D -- "True" --> E["Execute Block 1"];
D -- "False" --> F{"Loop (for/while)"};
E --> F;
F -- "Repeat" --> G["Perform Action in Loop"];
F -- "Done" --> H{"Call Function"};
G --> H;
H --> I{"Manipulate Data Structures (Lists/Dicts)"};
I --> J["End Program"];
3. Worked Example
Let's build a small program that takes a list of scores, calculates the average, and determines if the student passed (average >= 60).
def calculate_average(scores_list):
"""Calculates the average of a list of scores."""
if not scores_list: # Handle empty list to avoid division by zero
return 0
total = sum(scores_list)
return total / len(scores_list)
# Student's scores
student_scores = [75, 80, 55, 90, 60]
# Calculate the average
average_score = calculate_average(student_scores)
print(f"Student's scores: {student_scores}")
print(f"Average score: {average_score:.2f}") # Format to 2 decimal places
# Determine pass/fail
passing_threshold = 60
if average_score >= passing_threshold:
print("Result: Passed!")
else:
print("Result: Failed.")
# Example with an empty list
empty_scores = []
empty_average = calculate_average(empty_scores)
print(f"\nAverage for empty list: {empty_average}")
4. Key Takeaways
- Variables are named storage for different types of data.
- Operators let you manipulate values and make comparisons.
if/elsestatements enable decision-making in your code.forandwhileloops automate repetitive tasks efficiently.- Functions encapsulate reusable code, making programs modular.
- Lists store ordered collections, and dictionaries store key-value pairs.
- Understanding the flow of your program is crucial for debugging and design.
Common Mistakes to Avoid:
- Forgetting to indent code blocks correctly after if, else, for, while, or def.
- Infinite loops: Not changing the condition in a while loop so it never becomes False.
- TypeError or NameError: Using a variable before it's defined, or trying to do an operation on incompatible types (e.g., adding a string to an integer without conversion).
- Off-by-one errors: Forgetting that list indices start at 0.
5. Now Try It
Create a Python script that asks the user for three of their favorite foods. Store these foods in a list. Then, print each food item along with its position (1st, 2nd, 3rd) using a for loop and an f-string. Success means your output clearly shows the numbered list of foods the user entered.
Frequently asked about Review
Study this next
Get the full Python Programming Notes curriculum
Clone the complete plan to your dashboard for unlimited AI-generated notes, practice quizzes, and a personalised revision schedule.
Save this course free