In Python, how do I have a single backslash element in a list?

When printing a list in python the repr() method is called in the background. This means that print(list_of_strings) is essentially the same thing (besides the newlines) as:

>>> for element in list_of_strings:
...     print(element.__repr__())
... 
'<'
'>'
'€'
'£'
'$'
'¥'
'¤'
'\\'

In actuality the string stored is ‘\’ it’s just represented as ‘\\’

>>> for element in list_of_strings:
...     print(element)
... 
<
>
€
£
$
¥
¤
\

If you print out every element individually as above it will show you the literal value as opposed to the represented value.

Leave a Comment