Python Foundations

Your first steps in code: from print("Hello") to a game-playing AI.

  • Beginner
  • About 24 hours
  • 7 sections · 50 lessons
  • Free, no account

0 of 14 lessons complete

The course tutor, a friendly robot

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 programs7 lessons · 1 h 48 min

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.

Section overview

  1. What is programming?Lesson · 12 min
  2. Values and typesLesson · 12 min
  3. Variables: names for valuesLesson · 15 min
  4. Numbers and arithmeticLesson · 15 min
  5. Strings: working with textLesson · 15 min
  6. Comments and reading error messagesLesson · 14 min
  7. Lab: a receipt printer + section quizLab · 25 min

0 of 7 lessons complete

Section 2Decisions and loops7 lessons · 1 h 51 min

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.

Section overview

  1. True, False and comparisonsLesson · 12 min
  2. Making decisions: if, elif and elseLesson · 15 min
  3. Repeating with whileLesson · 15 min
  4. Counting loops: for and rangeLesson · 15 min
  5. Leaving early: break and continueLesson · 14 min
  6. Tracing and debuggingLesson · 15 min
  7. Lab: a number-guessing game + section quizLab · 25 min

0 of 7 lessons complete

Section 3Collections: lists, tuples, dictionaries and setsComing soon

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.

  1. ListsLesson · 14 min
  2. Indexing and slicingLesson · 14 min
  3. Changing lists: methodsLesson · 12 min
  4. TuplesLesson · 10 min
  5. DictionariesLesson · 15 min
  6. SetsLesson · 10 min
  7. Nesting and comprehensionsLesson · 15 min
  8. Lab: a gradebook + section quizLab · 25 min
Section 4FunctionsComing soon

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.

  1. Defining and calling functionsLesson · 14 min
  2. Parameters and return valuesLesson · 15 min
  3. Scope: where names liveLesson · 12 min
  4. Default and keyword argumentsLesson · 12 min
  5. Docstrings and readable functionsLesson · 10 min
  6. Functions as values and lambdaLesson · 14 min
  7. A first look at recursionLesson · 15 min
  8. Lab: a unit converter library + section quizLab · 25 min
Section 5Working with data: text, files and modulesComing soon

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.

  1. String methods and f-stringsLesson · 15 min
  2. Reading and writing filesLesson · 14 min
  3. CSV and JSONLesson · 15 min
  4. Handling errors with try and exceptLesson · 14 min
  5. Modules and importLesson · 12 min
  6. A tour of the standard libraryLesson · 15 min
  7. Lab: analyse weather data + section quizLab · 25 min
Section 6Objects and classesComing soon

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.

  1. Why objects?Lesson · 10 min
  2. Classes, attributes and methodsLesson · 15 min
  3. __init__ and __repr__Lesson · 12 min
  4. Inheritance and compositionLesson · 15 min
  5. DataclassesLesson · 12 min
  6. Lab: an inventory model + section quizLab · 25 min
Section 7Thinking like a programmerComing soon

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.

  1. Decomposing problemsLesson · 12 min
  2. What is an algorithm?Lesson · 12 min
  3. Searching and sortingLesson · 18 min
  4. How fast is it? Big-O intuitionLesson · 14 min
  5. Testing with assertLesson · 12 min
  6. Reading other people's codeLesson · 12 min
  7. Capstone: a tic-tac-toe AI with minimaxLab · 40 min