0
votes

How to insert "\\\" in a string in python. It seems to give Error

SyntaxError: EOL while scanning string literal

3
You can also do this. print ('\\'*3) - Joe Ferndz

3 Answers

1
votes

You can use string concat option to get as many \ as you want.

If you want 3 \ then you can do:

print ('\\'*3)

If you want 8 \, then you can just do:

print ('\\'*8)

This will eliminate the need to keep typing \\\\ many times.

Here's a way to add it to a variable and use it for printing later:

>>> x = 'This is an example for '+'\\'*3+' 3 backslashes'
>>> print (x)
This is an example for \\\ 3 backslashes
1
votes

We can insert \ from single print('\\')

so you wanted to type \\\\\\ then use six '\\' to get '\\\\\\' such as

print('\\\\\\\\\\\\')
0
votes

Yes because \ means break in Python.

\\ equals \but if you use 3 you are breaking something again.