Chapter 3: Functions Introduction

Remember from Chapter 1, encapsulation is the idea of giving a name to an algorithm and allowing us to refer to all of the instructions by merely referencing its name. Python allows us to do this through a mechanism called functions. Functions allow us to give a name to a block of Python code. If we implement an algorithm as a function in Python, we can run the algorithm by using the function’s name in a Python program. We refer to this process as calling the function.

Section 3.1 of this chapter introduces functions as a method of abstraction and their relationship to algorithms. Section 3.2 discusses the Python syntax for calling functions. Finally, section 3.3 introduces the Python language syntax for defining functions so that we can implement algorithms as functions.