Python Forum
The use of escape char \ - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: The use of escape char \ (/thread-20135.html)



The use of escape char \ - hishamzero1 - Jul-29-2019

Hi

I just was playing with strings in interpreter and some stranger result came when insert / escape char between two comma "" a screenshot (attached)
[Image: JxpmxHz]
Python version
Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03)


RE: The use of escape char \ - metulburr - Jul-29-2019

\a is a special character

If you want \a in the string you have to escape the escape character too
>>> '\\a'
'\\a'
>>> r'\a'
'\\a'
>>> '\a'
'\x07'
The result of the double backslash is actually what you want as it is escaping the escape character. It shows the final output. It does this in the python interpreter, but not when you print it.
>>> print('\\a')
\a
>>> print('\a')

>>> print(r'\a')
\a



RE: The use of escape char \ - hishamzero1 - Aug-12-2019

Thanks this solved it.