Python Foundations
Your first steps in code: from print("Hello") to a game-playing AI.
0 of 14 lessons complete

About this course
A gentle, hands-on first course in programming for people who have never written a line of code. You will write and run real Python right here in the browser, change it, break it on purpose and learn to read what the computer tells you back. Every idea comes with small runnable examples, exercises that check your work and tell you what to fix, and interactive graphics that show what a program does step by step: values living in memory, decisions as forks in a flowchart, loops going round and round. By the end you will organise data, write functions and classes, work with files, and finish by building a tic-tac-toe player that thinks ahead, the first AI of the path. No installs and no prior experience needed.
Before you start
No background needed: this is a starting point.
Part of the AI from Zero learning path (course 1 of 8).
What you'll learn
- Explain what a program is and run, edit and debug Python code in the browser
- Work with numbers, text and true-or-false values, and store them in variables
- Read Python's error messages and use them to find and fix mistakes
- Make programs decide with if, elif and else, and repeat work with while and for loops
- Trace a program by hand, line by line, to predict exactly what it will do
- Organise data with lists, tuples, dictionaries and sets
- Break problems into reusable functions with parameters and return values
- Read and write files, CSV and JSON, and handle errors gracefully
- Model real things with classes and objects
- Think like a programmer: decompose problems, search and sort, test with assert, and build a small game-playing AI
Syllabus
Section 1First steps: values, variables and your first programs
What programming is and how a computer runs your code, one line at a time. You will print messages, meet numbers, text and true-or-false values, store them in variables, do arithmetic, glue text together, write comments and learn to read error messages calmly. The lab ties it together in a receipt printer.
- What is programming?
- Values and types
- Variables: names for values
- Numbers and arithmetic
- Strings: working with text
- Comments and reading error messages
- Lab: a receipt printer + section quiz
0 of 7 lessons complete
Section 2Decisions and loops
Programs that choose and repeat. True and False and the comparisons that produce them, if, elif and else, while loops, for loops with range, and break and continue. You will learn to trace a program by hand and hunt bugs, then build a number-guessing game against a computer that picks its secret number.
- True, False and comparisons
- Making decisions: if, elif and else
- Repeating with while
- Counting loops: for and range
- Leaving early: break and continue
- Tracing and debugging
- Lab: a number-guessing game + section quiz
0 of 7 lessons complete
Section 3Collections: lists, tuples, dictionaries and sets
Keeping many values together. Lists and how to index and slice them, list methods, tuples, dictionaries for looking things up by name, sets for uniqueness, nesting one inside another and comprehensions. The lab builds a gradebook.
- Lists
- Indexing and slicing
- Changing lists: methods
- Tuples
- Dictionaries
- Sets
- Nesting and comprehensions
- Lab: a gradebook + section quiz
Section 4Functions
Packaging code into reusable pieces. Defining and calling functions, parameters and return values, scope, default and keyword arguments, docstrings, functions as values and lambda, and a first look at recursion. The lab builds a unit converter library.
- Defining and calling functions
- Parameters and return values
- Scope: where names live
- Default and keyword arguments
- Docstrings and readable functions
- Functions as values and lambda
- A first look at recursion
- Lab: a unit converter library + section quiz
Section 5Working with data: text, files and modules
Real programs read and write data. String methods and f-strings, files in the browser's own file system, CSV and JSON, handling errors with try and except, modules and import, and a tour of the standard library. The lab analyses a CSV of weather data.
- String methods and f-strings
- Reading and writing files
- CSV and JSON
- Handling errors with try and except
- Modules and import
- A tour of the standard library
- Lab: analyse weather data + section quiz
Section 6Objects and classes
Modelling things that have data and behaviour. Why objects help, classes, attributes and methods, __init__ and __repr__, inheritance and composition, and dataclasses. The lab builds a tiny inventory model.
- Why objects?
- Classes, attributes and methods
- __init__ and __repr__
- Inheritance and composition
- Dataclasses
- Lab: an inventory model + section quiz
Section 7Thinking like a programmer
The habits that make hard problems manageable. Decomposing problems, algorithms, searching and sorting made visible, an intuition for Big-O, testing with assert and reading other people's code. The capstone builds a tic-tac-toe player that looks ahead with minimax, the first AI of the path.
- Decomposing problems
- What is an algorithm?
- Searching and sorting
- How fast is it? Big-O intuition
- Testing with assert
- Reading other people's code
- Capstone: a tic-tac-toe AI with minimax