Examples of Python source code or interactive sessions are represented as \verbatim environments. This environment is a standard part of LATEX. It is important to only use spaces for indentation in code examples since TEX drops tabs instead of converting them to spaces.
Representing an interactive session requires including the prompts and output along with the Python code. No special markup is required for interactive sessions.
Within the \verbatim environment, characters special to LATEX do not need to be specially marked in any way. The entire example will be presented in a monospaced font; no attempt at ``pretty-printing'' is made, as the environment must work for non-Python code and non-code displays.
The Python Documentation Special Interest Group has discussed a number of approaches to creating pretty-printed code displays and interactive sessions; see the Doc-SIG area on the Python Web site for more information on this topic.