# listings: using Python and Matlab code [duplicate]

Can I \lstset to define both Matlab code and Python code? or will last one override the first one? or does listings know the difference when there is a .m or .py extension and use the correct \lstset?

## marked as duplicate by egreg, Werner, jub0bs, mafp, Stefan Kottwitz♦Sep 26 '13 at 22:41

You can do:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[language=Python, caption={Some Python code}]
class example(object):
pass
\end{lstlisting}
\begin{lstlisting}[language=Matlab, caption={Some Matlab code}]
function [y1, y2] = funfun(x1, x2)
disp(x1)
end
\end{lstlisting}
\end{document}


Or you can \lstset the language before the listing.