Start with your first line of code, understand how programs make decisions, work with real information and finish by planning a practical automation project. Every lesson includes an explanation, an example and something to try.
✓ Beginner-friendly explanations✓ Practical examples✓ Progress saved in this browser
MODULE 01 · 4 LESSONS
Start with Python
Understand the language, set up your workspace and write your first programs.
LESSON 01 OF 04
What Python is and where it is used
Python is a general-purpose programming language. Its readable syntax makes it approachable for beginners, while its libraries make it useful in automation, websites, data analysis, artificial intelligence and everyday scripting.
How a Python program works
You write instructions in a text file, usually ending in .py. The Python interpreter reads those instructions and executes them. Unlike a web page, a Python script normally runs in a Python environment on your computer or server.
Where you will see Python
A small script can rename files or organise folders. A web application can use Python on its server. Data teams use it to clean and analyse information, and AI teams use it to prepare data and work with models.
CODE EXAMPLEPython
print("Hello, B Tecky!")
print("I am learning Python.")
YOUR PRACTICE TASK
Try it yourself
In your own words, write down two tasks Python could help you with. Choose one small task that you would like to automate.
LESSON 02 OF 04
Install Python and choose an editor
A useful setup has two parts: the Python interpreter, which runs your code, and a code editor, where you write and organise it.
Check your installation
After installing Python from the official Python website, open a terminal and try python --version. On some systems the command is python3 --version. A version number means the interpreter is available in that terminal.
Choose a workspace
You can begin with a simple editor or use an IDE such as Visual Studio Code. Create a folder for your experiments and save your first file as hello.py. Keeping projects in separate folders makes files easier to find later.
CODE EXAMPLEPython
python --version
# If your system uses python3:
python3 --version
YOUR PRACTICE TASK
Try it yourself
Create a folder named python-practice and save a file named hello.py inside it. Run the file from your terminal.
LESSON 03 OF 04
print(), comments and input()
Programs become useful when they can display information and receive information from people. Python provides simple built-in tools for both.
Display information with print()
print() sends text or values to the output. Text is written inside quotation marks. You can print several values by separating them with commas.
Add notes with comments
A hash symbol (#) starts a comment. Python ignores the comment when it runs your program. Comments should explain why something is happening when the code is not already clear.
Ask a question with input()
input() displays a prompt and waits for the user to type a response. It returns that response as text, even if the person types digits.
CODE EXAMPLEPython
name = input("What is your name? ")
# Greet the person who is using the program
print("Welcome to Python,", name)
YOUR PRACTICE TASK
Try it yourself
Ask for a person’s name and favourite technology, then print a friendly two-line introduction.
LESSON 04 OF 04
Variables, values and basic types
A variable is a name that refers to a value. Variables let a program remember information and use it again.
Choose clear variable names
Names such as learner_name and course_count explain what a value represents. Python variable names are case-sensitive, cannot start with a digit and should not contain spaces.
Know the common types
str stores text, int stores whole numbers, float stores decimal numbers and bool stores True or False. Use type(value) when you want to inspect a value’s type.
Convert input when doing maths
Because input() returns text, convert numeric input with int() or float() before arithmetic. Conversion only works when the text represents a valid number.
Build a learner profile with a name, age, hours studied and a Boolean value that records whether the learner is active.
MODULE 01 · KNOWLEDGE CHECK
Check your understanding
What type of value does input() return by default?
MODULE 02 · 4 LESSONS
Logic and reusable code
Make decisions, repeat instructions and organise programs into functions.
LESSON 01 OF 04
Comparisons and Boolean logic
Programs often need to compare values before deciding what to do. A comparison produces a Boolean result: True or False.
Comparison operators
Use == to test equality, != for inequality, > and < for greater or less than, and >= or <= for inclusive comparisons. A single = assigns a value; it does not test equality.
Combine conditions
and requires both conditions to be true, or requires at least one, and not reverses a Boolean value. Use parentheses when they make a complex condition easier to understand.
Create two conditions for a course: one that checks whether a learner passed and another that checks whether they earned a distinction.
LESSON 02 OF 04
Make decisions with if, elif and else
Conditional statements let a program choose which instructions to run. Python uses indentation to show which instructions belong to each branch.
Build a decision
Start with if and a condition. Add elif for another condition and else for the fallback case. The first matching branch runs; the remaining branches are skipped.
Keep conditions readable
Use clear comparisons and avoid deeply nested decisions when a simple sequence of elif branches will do. Consistent four-space indentation is the common Python convention.
Write a grade checker with at least three outcomes. Decide what should happen for scores below 40, from 40 to 69, and 70 or above.
LESSON 03 OF 04
Repeat work with for and while loops
Loops repeat a block of code. Use a for loop when you are going through a sequence, and a while loop when repetition depends on a condition.
The for loop
for item in sequence visits each item. range(5) produces five numbers starting at zero: 0 through 4. The ending value is not included.
The while loop
A while loop continues while its condition is true. Make sure something inside the loop can eventually make the condition false, otherwise the loop may never stop.
Control a loop
break exits a loop early. continue skips the rest of the current iteration and moves to the next one. Use these sparingly so the flow stays easy to follow.
CODE EXAMPLEPython
for number in range(1, 6):
print("Number:", number)
countdown = 3
while countdown > 0:
print(countdown)
countdown -= 1
print("Go!")
YOUR PRACTICE TASK
Try it yourself
Print the numbers from 1 to 10, then write a countdown that ends with the message “Ready!”
LESSON 04 OF 04
Create functions and return values
Functions package instructions into reusable units. They help you avoid repetition and give meaningful names to steps in a program.
Define and call a function
Use def followed by a function name and parentheses. The indented body contains its instructions. Calling the function runs that body.
Parameters and return
Parameters are inputs a function receives. return sends a result back to the caller. A function that only prints a value does not automatically return that value.
Create a function that accepts a quiz score and returns whether the learner passed. Call it with at least two different scores.
MODULE 02 · KNOWLEDGE CHECK
Check your understanding
Which keyword sends a result back from a function?
MODULE 03 · 4 LESSONS
Work with real information
Store collections of values, work with files and handle errors safely.
LESSON 01 OF 04
Lists, tuples, sets and dictionaries
Collections let you keep related values together instead of creating a separate variable for every item.
Choose the right collection
A list is ordered and changeable. A tuple is ordered and cannot be changed after creation. A set stores unique values. A dictionary stores key-value pairs so you can look up a value using a meaningful key.
Access and update values
List positions start at zero. Dictionaries are accessed by key. Use methods such as append() to add to a list and get() to safely read a dictionary value that may not exist.
Create a list of five learning topics and a dictionary describing a learner. Read and update at least one value in each.
LESSON 02 OF 04
Read and write text files
Files allow a program to keep information after it finishes running. Python’s with statement helps close files safely.
Open a file
Use open() with a mode such as r to read, w to write (replacing existing content), or a to append. The with statement manages closing the file even if an error occurs.
Read and write content
write() stores text. read() reads the content, while readline() reads one line. For everyday text files, specify encoding="utf-8" to handle a broad range of characters consistently.
CODE EXAMPLEPython
with open("notes.txt", "w", encoding="utf-8") as file:
file.write("My Python learning notes\n")
with open("notes.txt", "r", encoding="utf-8") as file:
notes = file.read()
print(notes)
YOUR PRACTICE TASK
Try it yourself
Write three study notes to a text file, then read the file and display its contents.
LESSON 03 OF 04
Handle errors with try and except
Errors are a normal part of programming. Handling expected problems helps your program respond clearly instead of stopping unexpectedly.
Catch specific errors
Place code that may fail inside try. Use except with a specific exception such as ValueError when a text-to-number conversion fails. Avoid catching every possible error without a reason.
Use else and finally
An optional else block runs when the try block succeeds. finally runs whether an exception happened or not, making it useful for cleanup tasks.
CODE EXAMPLEPython
value = input("Enter a whole number: ")
try:
number = int(value)
except ValueError:
print("Please enter digits such as 12.")
else:
print("Double:", number * 2)
YOUR PRACTICE TASK
Try it yourself
Ask for an amount and convert it to a number. Show a helpful message when the person enters invalid text.
LESSON 04 OF 04
Use modules and packages
Modules let you reuse code from Python’s standard library or from packages you install. This keeps projects smaller and better organised.
Import standard tools
import math makes the math module available. You can use a specific function with from math import sqrt. Prefer clear imports so readers can see where a function comes from.
Organise your own code
A Python file can be imported as a module by another file. Keep related functions together and choose filenames that do not conflict with standard-library module names.
CODE EXAMPLEPython
import random
from math import sqrt
secret_number = random.randint(1, 10)
print("A square root example:", sqrt(81))
print("Your practice number:", secret_number)
YOUR PRACTICE TASK
Try it yourself
Use the random module to select a number and the math module to calculate a square root. Explain what each import provides.
MODULE 03 · KNOWLEDGE CHECK
Check your understanding
Which collection stores key-value pairs?
MODULE 04 · 4 LESSONS
Build useful automations
Work with structured data, APIs, project structure and testing habits.
LESSON 01 OF 04
Work with CSV and JSON
CSV and JSON are common formats for exchanging structured information. Python includes standard-library modules to read and write both.
CSV tables
CSV stores rows and columns as text. The csv module can read each row and write new rows. Use newline="" when opening CSV files for writing to avoid extra blank lines on some platforms.
JSON data
JSON represents objects, arrays, strings, numbers and Boolean values. json.load() reads JSON from a file, while json.dump() writes Python data to a file.
CODE EXAMPLEPython
import json
learner = {"name": "Aarav", "completed": 4}
with open("learner.json", "w", encoding="utf-8") as file:
json.dump(learner, file, indent=2)
with open("learner.json", encoding="utf-8") as file:
saved_learner = json.load(file)
print(saved_learner["name"])
YOUR PRACTICE TASK
Try it yourself
Save a small learner record as JSON, load it again and display two fields from the saved record.
LESSON 02 OF 04
Make HTTP requests and understand APIs
An API is a defined way for software systems to exchange information. Many web APIs use HTTP requests and return JSON responses.
Understand a request
A client sends a request to an endpoint. The server responds with a status code and, often, data. A 200-level status usually indicates success; 400-level responses indicate a client-side problem and 500-level responses indicate a server-side problem.
Use requests carefully
The popular requests package can send HTTP requests. Check the response status, handle network errors and respect the API’s usage rules. Never place private API keys directly in code that you publish.
Describe an API you might use in a project. Identify its endpoint, the information you would request and how your program should handle a failed request.
LESSON 03 OF 04
Organise a multi-file Python project
As a program grows, splitting it into focused files makes it easier to understand, test and maintain.
A simple project layout
Keep the main entry point separate from reusable functions. A small project might contain main.py, helpers.py, a data folder and a README.md file explaining how to run it.
Use a virtual environment
A virtual environment isolates packages for one project. Create it with python -m venv .venv, activate it using the command for your operating system, and install project dependencies inside it.
Plan a folder structure for your report generator. Separate the main program, reusable calculations, input data and documentation.
LESSON 04 OF 04
Test, debug and document your program
Reliable programs are built through small checks, clear error messages and documentation that helps another person use the project.
Debug systematically
Read the full error message and identify the file and line where it occurred. Reproduce the problem with a small input, inspect relevant values and change one thing at a time.
Write tests
A test checks whether code behaves as expected. Python’s unittest module is included with Python. Test normal inputs, boundary values and invalid inputs rather than checking only one happy path.
Document how to run it
A README should explain the project purpose, setup, dependencies, run command, example input and known limitations. Good documentation makes a project easier to share and maintain.
CODE EXAMPLEPython
def calculate_total(price, quantity):
if price < 0 or quantity < 0:
raise ValueError("Values cannot be negative")
return price * quantity
assert calculate_total(10, 3) == 30
print("Basic check passed")
YOUR PRACTICE TASK
Try it yourself
Write a README outline for your final project and list three test cases: a normal case, a boundary case and an invalid-input case.
MODULE 04 · KNOWLEDGE CHECK
Check your understanding
Why should you set a timeout on an HTTP request?
YOUR PYTHON CAPSTONE
Build a productivity toolkit.
Bring your skills together in a command-line toolkit that includes a quiz, an expense tracker that saves information to a file, and a report generator that reads structured data and produces a useful summary.
Plan the tools and decide what information each one needs.
Use functions and conditions to organise the program.
Save and load information with files, CSV or JSON.
Handle invalid input, test important cases and document how to run it.
What you should be able to explainHow your program receives input, makes decisions, stores information, handles errors and produces an output.