Functions

Experience has shown that the best way to develop and maintain a large program is to construct it from smaller, more manageable pieces. This technique is called divide and conquer, which is accomplished through a programming concept called functions. Functions are blocks of code that a computer can follow in order to complete a specific task.

Using existing functions as building blocks for creating new programs is a key aspect of software reusability—it’s also a major benefit of programming with Python. Packaging code as a function allows you to execute it from various locations in your program just by calling the function, rather than duplicating the possibly lengthy code. This also makes programs easier to modify. When you change a function’s code, all calls to the function execute the updated version.