I program in Python in PyCharm and whenever I write '\' as a string it says that the following statements do nothing. For example:
Is there a way to fix this and make it work? Thanks.
I program in Python in PyCharm and whenever I write '\' as a string it says that the following statements do nothing. For example:
Is there a way to fix this and make it work? Thanks.
You need to double the backslash:
'/-\\'
as a single backslash has special meaning in a Python string as the start of an escape sequence. A double \\
results in the string containing a single backslash:
>>> print '/-\\'
/-\
If the backslash is not the last character in the string, you could use a r''
raw string as well:
>>> print r'\-/'
\-/
You need to scape them to be in the string, for example:
>>>s='\\'
>>>print s
\
You can also use the r
(raw string) modifier in front of the string to include them easily but they can't end with an odd number of backslash. You can read more about string literals on the docs.