6.4 Parameters, Parameter Passing, and Scope

Throughout the previous chapters, we have used functions to implement abstraction. We have broken problems down into smaller, more manageable pieces and have implemented functions that we can call over and over again. In the previous section we pushed this idea one step further by passing functions as parameters to other functions. In this section we explore in more detail the underlying mechanics of functions and parameter passing.

Consider the function shown in LISTING 6.7, which computes the hypotenuse of a right triangle. Using the Pythagorean theorem, a2 + b2 = c2, this function needs the lengths of the two sides, called a and b, and computes and returns the length of the long side, called ...

Get Python Programming in Context, 3rd 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.