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?

20th May 2019, 10:00 PM
Sohrab
3 Respuestas
+ 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")
20th May 2019, 11:53 PM
D_Stark
D_Stark - avatar
+ 4
I'm not clear as to what you are asking. Pls expanciate
20th May 2019, 10:05 PM
Jella
Jella - avatar
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.
21st May 2019, 2:52 AM
Choe
Choe - avatar