Python includes several modules for implementing algorithms elegantly and concisely using whatever style is most appropriate for the task. It supports purely procedural, object oriented, and functional styles and all three styles are frequently mixed within different parts of the same program.
functools includes functions for creating function decorators,
enabling aspect oriented programming and code reuse beyond what a
traditional object oriented approach supports. It also provides a
class decorator for implementing all of the rich comparison APIs using
a short-cut, and
partial objects for creating references to
functions with their arguments included.
itertools module includes functions for creating and
working with iterators and generators used in functional programming.
operator module eliminates the need for many trivial lambda
functions when using a functional programming style by providing
function-based interfaces to built-in operations such as arithmetic or
And no matter what style is used in a program,
resource management easier, more reliable, and more concise.
Combining context managers and the with statement reduces
the number of try:finally blocks and indentation levels
needed, while ensuring that files, sockets, database transactions, and
other resources are closed and released at the right time.