-1
print "\\"

It print me enter image description here in console...

But I want to get string \

How to get string string \?

somputer
  • 235
  • 2
  • 8

2 Answers2

3

There's clearly some sort of configuration with your console that's wrong. Doing this:

print "\\"

Clearly prints \ for me.

Ethan Bierlein
  • 3,353
  • 4
  • 28
  • 42
1

You can add letter r to string before quotes (r for raw). It will ignore all special symbols.

For example

>>> print '\x63\\ Hello \n\n8'
c\ Hello

8
>>> print r'\x63\\ Hello \n\n8'
\x63\\ Hello \n\n8

So printing backslash is print r'\'

  • This rapidly becomes the better answer when you have more than one special character in your string! – nigel222 Sep 10 '15 at 08:30