He could have invested in a Python syntax highlighter. I use minted, myself, but I'm sure there are many alternatives.
https://websites.umich.edu/~mejn/cp2/exercises.html
By the way, I use typst now, so I don't have to worry about highlighting anymore!