Functions

def makes a function. Parameters go in the parentheses, and return sends a value back to the caller.

Type hints like values: list[float] and -> float | None say what goes in and what comes out. Python doesn't enforce them, but they make code easier to read, editors and type checkers use them, and interviewers notice them.

The docstring under the def says what the function does. The >>> lines are a doctest: an example call and its expected output. Every function in this tour has one, so you can see the shape of the input at a glance.

Code under if __name__ == "__main__": runs when you press Run, but not when the tests import your file.

Exercise: finish mean so it returns the average of a list of numbers, and returns None for an empty list instead of crashing with ZeroDivisionError. Press Check to run the tests.