The problem has nothing to do with the list. What is broken in your snippet is just a string literal. Easiest way to reproduce would be something like print('\')
. It happens because certain symbols needs to be escaped in strings. For instance, if you want to encode a new line symbol in a string, you could do it as follows print('foo\nbar')
and \n
here means a line delimiter symbol. Notice, that its a compound symbol and \
is used as its first part.
So, getting back to your example, what is really happening is you are trying to escape the following symbol after slash, i.e. the single quote. And you succeed! However, then the whole string literal starts missing the closing quote. How to fix it? Escape the escape symbol:
lst = ['\\']