Chapter 8: Functions
So far, we’ve learned quite a bit about coding, and if you’ve been completing the challenges, you’ve already put together some small bits of code. Wouldn’t it be great if we could save those bits of code and run them at any time in a program? That’s what we can use functions for!
In this chapter, we’ll cover:
- defining functions
- calling a function
- return values
- parameters and arguments
- choosing the right type of function
A function is a block of code that’s almost like a small, self-contained mini program. They can help to reduce repetition and make code easier to follow.
Functions are a perfect application of the DRY principle (“don’t repeat yourself”). We should always be trying to not repeat ourselves, thus ...
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.