-1
print "\\"

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

But I want to get string \

How to get string string \?

3
  • The statement you gave correctly prints the `\` for me. Is this the only thing printing wrongly, does it get printed wrongly, even if surrounded by other characters? Commented Sep 10, 2015 at 1:40
  • 2
    duplicate? stackoverflow.com/questions/6477823/… Commented Sep 10, 2015 at 1:41
  • what operating system? Commented Oct 5, 2016 at 23:07

2 Answers 2

3

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

print "\\"

Clearly prints \ for me.

Sign up to request clarification or add additional context in comments.

Comments

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'\'

1 Comment

This rapidly becomes the better answer when you have more than one special character in your string!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.