0

In python3.6, I tried

In [60]: a = '\a'
In [61]: b = '\b'
In [62]: c = '\c'
In [63]: l =[a, b, c]

If test l

In [64]: l
#it output following list instead of  ['a','\b','\c']
Out[64]: ['\x07', '\x08', '\\c']

encapsulate them directly in a list.

In [70]: ['\a','\b','\c']
#it output following list instead of  ['a','\b','\c']
Out[70]: ['\x07', '\x08', '\\c']

What's the mechanism behind it?

Wizard
  • 173
  • 2
  • 7

1 Answers1

1

Backslash is the escape character to allow you to enter non-printable characters into a string literal.

One of the most known escape sequences for example is \n for a newline.

\a is the bell character and \b is the backspace character.

ratchet freak
  • 4,406
  • 1
  • 17
  • 14