Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Organizing Your Kitchen (Functions & Imports)

As you write more code, your programs can start to look like a messy kitchen during a holiday dinner. Ingredients are scattered, steps are repeated, and finding the right utensil becomes a huge chore. A great chef isn't just someone who can cook—it's someone who keeps their kitchen organized so they can create amazing dishes efficiently.

This module is all about turning our code into a well-organized cookbook. We'll learn how to create reusable sets of instructions, make them flexible, get useful results back from them, and stock our kitchen with powerful pre-made tools.

  • Setting Up Your Kitchen Stations (Functions): Every great recipe involves repeating the same setup steps. Instead of rewriting these instructions every time, you'll learn how to define a named procedure (a function) once, and then call it whenever you need it, just like setting up your cooking station before you start a new dish.

  • Passing in Your Ingredients (Function Parameters): A recipe for "bake" is more useful if you can specify what you're baking and at what temperature. We'll explore how to add placeholders (parameters) to our functions, allowing us to pass in different "ingredients" (arguments) each time we call them, making our recipes flexible and powerful.

  • Returning the Finished Dish (Function Returns): Some recipes don't just perform an action; they produce a result you can use—like a sauce you can add to pasta. You'll learn how functions can return a finished product, allowing you to store it, combine it with other results, and build more complex programs from these modular building blocks.

  • Stocking Your Kitchen with Gadgets (Imports): A chef doesn't build their own stand mixer. They use powerful, pre-made tools to get the job done faster. We'll show you how to import external libraries—your programming "kitchen gadgets"—to add sophisticated features to your programs without having to build them from scratch.

Let's learn how to code like a head chef.