Any modern programming language needs to have some way of combining functionality into reusable chunks of code. In Python, one of the most basic units of reusable code is the function. In this chapter, you will look at how functions work within Python, as well as some places where they may do something surprising.
6-1. Creating Basic Functions
You want to create a basic function to handle a simple task, such as finding the square of two.
Within Python, you can use the built-in def keyword to create a new function.
How It Works
Listing 6-1 shows an example.