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.
- Defining and calling functions: Define functions with
def, pass arguments, and return values. ~20 min - Scope: where names live: Find out where a name can be read and changed, and when to use
global. ~15 min - Recursion basics: Write a function that calls itself, with a base case that stops it. ~20 min
- Modules and imports: Import standard library modules, and split your own code into files. ~15 min
- Files and exceptions: Write and read text files, and catch errors with
tryandexcept. ~25 min