4. Control Structures and Functions

This chapter’s first two sections cover Python’s control structures, with the first section dealing with branching and looping and the second section covering exception-handling. Most of the control structures and the basics of exception-handling were introduced in Chapter 1, but here we give more complete coverage, including additional control structure syntaxes, and how to raise exceptions and create custom exceptions.

The third and largest section is devoted to creating custom functions, with detailed coverage of Python’s extremely versatile argument handling. Custom functions allow us to package up and parameterize functionality—this reduces ...

Get Programming in Python 3: A Complete Introduction to the Python Language, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.