In this chapter, we learned one of the main pillars of code – functions. Functions allow us to write concise and expressive code that can be reused multiple times. Functions serve as building blocks of our programs – be it report generation, interaction with the APIs, or training the model. We discussed how to declare both standard and anonymous functions, how to set arguments, and their default values, and how to use args and kwargs for more flexible interface design. We also learned how to write good quality documentation strings and add type annotations. Finally, we did rewrite our code from the previous chapter, using functions, which made it slightly more expressive and error-prone.
In the last section, we defined recursion – an approach where a function is called from within itself, and which allows us to solve rather complex tasks with simple...