I\'m using the following LaTeX code in a Beamer presentation:
\\begin{frame} \\begin{figure} \\centering \\tiny \\lstset{language=python} \
This has nothing to do with beamer; it's about a listings feature. Its excellent manual has more. For example:
beamer
listings
\lstinputlisting[firstline=2,lastline=5]{code/get_extent.py}