0
How to produce a single backslash in a text in Python?
So I am trying to get the following output: \ I want to use it as a text without using the print command. I know, using print command, print('\\') give me the desired output, but '\\' does not. For instance, print('hello world!') would return hello world and 'hello world!' would return 'hello world!'. So I am trying to return '\' without using print command. Can someone help me?
3 ответов
+ 6
You cant display anything unless you use a function to display your output to console. Backslash has a special meaning so you need to escape it everytime with another
print("hello\\world")
+ 4
I'm not clear as to what you are asking. Pls expanciate
0
judging by your question, you must be using the interactive python shell, but unfortunately, it wont work here. If you want string formatted output, use representations.
print(repr(“\\”))
of course, you will need a print.