Chapter 5. Functions

A function is a reusable chunk of code. It is a block of code with a name that takes input, provides output, and can be stored in files for later use. Pretty much any useful piece of Python code is stored in a function.

Python has excellent support for functions. For instance, it provides many ways to pass data into a function. It also lets you include documentation strings within the function itself so that you—or other programmers—can always read how the function works.

Once we learn about functions, we will be using them constantly. Thus it is important that you have a good grasp of how they work. As we will soon see, we must master a handful of details in order to completely understand functions. With practice, these details ...

Get Python: Visual QuickStart Guide, Second Edition 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.