LaTeX provides a listings package to typeset code. The standard output is great for black-and-white printouts, but not for beamer presentations, where a more dynamic color scheme would be suitable. Having recently worked on slides with Python code, I have prepared a file that you can include to get nice colourful code that looks good on a presentation:
My code is based on a snippet found on Ubuntu forums. I added some more keywords and tweaked the color scheme to correspond to the one that IDLE uses (that color scheme is not ideal, but my audience uses IDLE for coding and I wanted some consistency).
To use the package, copy the file to the same folder as your document and include it in the header:
\include{pythonlisting}
Then, to render code, use python sections:
\begin{python}
def foo():
print "bar"
\end{python}
Note that if you want to use this in a beamer frame, you will have to mark the frame that contains Python code as fragile, like this:
\begin{frame}[fragile]{Some Python code}
\begin{python}
def foo():
print "bar"
\end{python}
\end{frame}