Functions

functions
beginner
Package useful steps behind names so code can be reused, tested, and explained.

How to use this chapter hands-on

This chapter is about Functions. Do not read it like a reference manual. Use it as a sequence of short labs. For each lesson, open the Colab notebook from the button above, run Example 1, write a prediction, and then change one small part of the code.

By the end of the chapter, you should have one small artifact: a notebook, a script, a trace table, or a project note. The artifact should show one working example, one controlled variation, and one error or surprising result that you investigated calmly.

If time is short, study one lesson deeply instead of skimming all of them. A deeply understood example is one you can run again, explain in plain language, modify safely, and debug when it breaks.

Why this chapter matters

Package useful steps behind names so code can be reused, tested, and explained.

Lessons are now grouped by coherent learner topics. A page may contain multiple short quizzes when the page has multiple sections, so students can check one idea before moving to the next.

NoteGuiding questions
  • Which lessons belong in this chapter?
  • What should I review before moving on?
  • How do the lesson sections build one practical skill?

Lesson path

  • Function Basics — Define functions, pass arguments, return results, and understand scope.
  • Function Contracts — Use docstrings and type hints to communicate how functions should be used.
  • Decomposition and Testing — Break problems into functions and protect behavior with focused tests.

Chapter checkpoint

Use this short checkpoint before starting the chapter.

Back to top