Skip to content

Part 4: Functions and structure

This part shows how to name a step with a function, how names are visible inside and outside functions, how a function can call itself, how to use modules, and how to read files and handle errors. Work through the lessons in order, because each one uses the functions and names from the lessons before it.

  1. Defining and calling functions: Define functions with def, pass arguments, and return values. ~20 min
  2. Scope: where names live: Find out where a name can be read and changed, and when to use global. ~15 min
  3. Recursion basics: Write a function that calls itself, with a base case that stops it. ~20 min
  4. Modules and imports: Import standard library modules, and split your own code into files. ~15 min
  5. Files and exceptions: Write and read text files, and catch errors with try and except. ~25 min