How can I print the \ character in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How can I print the \ character in python?

9th Jun 2020, 3:23 PM
Chwenkam Adrian
6 Answers
+ 7
There is also an other possible solution. (Kirian Deep Naidu, you have been faster!) my_str = r'hello \\world\n' # this is a raw-string print(my_str) # output = 'hello \\world\n' (quotes are not printed)
9th Jun 2020, 4:02 PM
Lothar
Lothar - avatar
+ 3
print("\\")
9th Jun 2020, 3:39 PM
Arsenic
Arsenic - avatar
+ 2
Chwenkam Adrian You need to escape your backslash by preceding it with, another backslash: Example: print("\\")
9th Jun 2020, 3:59 PM
Indira
Indira - avatar
+ 1
you need to scape it using double \\
9th Jun 2020, 3:27 PM
Emanuel Maliaño
Emanuel Maliaño - avatar
+ 1
Yeah it works. Thanks!
9th Jun 2020, 7:44 PM
Chwenkam Adrian
0
It actually annuls the " in print("\"). I would like to create a house with it.
9th Jun 2020, 3:27 PM
Chwenkam Adrian