Conclusion
Functions let you name a computation and reuse it.
This chapter introduced the core function moves:
- define a function with
def - call a function with parentheses
- pass arguments into parameters
- return a value
- keep intermediate names local
- use simple defaults
- check functions with known inputs
- add a short docstring when it helps the reader
The most important distinction is between printing and returning. Printing shows a value to the reader. Returning gives a value back to the program.
What Comes Next
The next chapter turns to collections and iteration. Lists, tuples, dictionaries, and sets let programs hold many values. Functions will make those transformations easier to name and test.
Before moving on, make sure you can write and test:
Small functions like this become the building blocks of larger experiments.