Voici une solution :
% !TeX TS-program = xelatex
\documentclass[french]{article}
\usepackage{ifxetex}
\ifxetex
\usepackage{fontspec}
\else
\usepackage{lmodern}
\fi
%
\usepackage{babel}
\usepackage{listings}
\makeatletter
\def\lst@visiblespace{\lst@ttfamily{\textvisiblespace}}
\makeatother
%
\begin{document}%,showstringspaces=true]
\begin{lstlisting}[language=Python,showstringspaces=true,basicstyle=\ttfamily]
# un commentaire
i = 1
while i <= 5:
print(i)
i = i + 1
print('Fini !')
\end{lstlisting}
\end{document}
On obtient ceci :
![alt text][1]
[1]: https://texnique.fr/osqa/upfiles/Screen_Shot_2019-11-05_at_00.35.51.png