I want to add a backslash to a list in Python but it gives an error.
Output:
chars = [".", ",", "/", "\"]
^
SyntaxError: unterminated string literal (detected at line 8)
I want to add a backslash to a list in Python but it gives an error.
Output:
chars = [".", ",", "/", "\"]
^
SyntaxError: unterminated string literal (detected at line 8)
Backslashes allow you to enter characters that are normally used by the code, eg. " and '. To avoid the problem, simply just add another back slash. "\"
-> "\\"
It is giving an error because \
is an escape character, You can store this using escaping this another escape character
chars = [".", ",", "/", "\\"]