After inserting a Python file into my latex file via \lstinputlisting[language=Python]{Thesis.py}, I get
Normally, it should be ~, but it is at higher than it should be. When I copy it from the output PDF , I no longer get ~.
Could you please elaborate on this issue and how to get the normal ~?

\lstinputlisting[language=Python]{Thesis.py}, the command in your linked answer does work. I mean I insert Python code and not directly type it in my LaTex document. – Akira Jun 06 '20 at 21:12\lstinputlisting. So does the one withberamonoandfontenc, but note that it needsbasicstyle=\ttfamily. – Torbjørn T. Jun 06 '20 at 21:20beramonoandfontencdoes solve my problem. – Akira Jun 06 '20 at 21:28