Learning Python interpreter basics
In this recipe, we'll cover some of Python's built-in capabilities to examine code, investigate what's going on, and detect when things are not behaving properly.
We can also verify when things are working as expected. Remember that being able to rule out part of the code as the source of a bug is incredibly important.
While debugging, we typically need to analyze unknown elements and objects that come from an external module or service. Code in Python is highly discoverable at any point in its execution. This ability to examine the types and properties of the code while it is being executed is called introspection.
Everything in this recipe is included by default in Python's interpreter.
How to do it...
- Import
pprint
:>>> from pprint import pprint
- Create a new dictionary called
dictionary
:
...>>> dictionary = {'example': 1}