Chapter 5
Wrangling Bigger Chunks of Code
IN THIS CHAPTER
Creating a function
Commenting a function
Passing information to a function
Returning values from functions
Unmasking anonymous functions
In this chapter you learn how to better manage larger code projects by creating your own functions. Functions provide a way to compartmentalize your code into small tasks that can be called from multiple places within an app. For example, if something you need to access throughout the app requires a dozen lines of code, chances are you don’t want to repeat that code over and over again every time you need it. Doing so just makes the code larger than it needs to be. Also, if you want to change something, or if you have to fix an error in that code, you don’t want to have to do it repeatedly in a bunch of different places. If all that code were contained in a function, you would just have to change or fix it in that one location.
To access the task that the function performs, you just call ...
Get Python All-in-One For Dummies now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.