Chapter 2. Branching Using Dictionaries

Functions are objects like everything else in Python, and a function’s name is an object reference that refers to the function. If we write a function’s name without parentheses, Python knows we mean the object reference, and we can pass such object references around just like any others. We can use this fact to replace if statements that have lots of elif clauses with a single function call.

In the examples accompanying the book, Programming in Python 3: A Complete Introduction to the Python Language,[*] is an interactive console program called dvds-dbm.py, that has the following menu:

[*] All the examples are available for download from www.qtrac.eu/py3book.html.

(A)dd  (E)dit  (L)ist  (R)emove  (I)mport e(X)port  (Q)uit ...

Get Advanced Python 3 Programming Techniques 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.