Update Jan. 2021: It has come to my attention that starting with the 2020/02/02 version of the LaTex2e format, it is no longer necessary to load the textcomp
package in order to use the instruction \textquotesingle
. For more information about the changes brought about by the 2020/02/02 version of LaTeX, see https://www.latex-project.org/news/latex2e-news/ltnews31.pdf.
(The answer I posted back in September 2014 follows. I suppose it is now mainly (purely?!) of historical relevance.)
You may have forgotten to load the textcomp package, which defines the macro \textquotesingle
. With the package loaded, your code doesn't throw an error.
By the way, the curly braces after each \textquotesingle
and around the square brackets aren't needed. I'd omit them, to reduce code clutter.

\documentclass{article}
\usepackage{textcomp}
\begin{document}
\texttt{man1 = Person(\textquotesingle M\textquotesingle, 1, [2, 1])}
\end{document}