user2117821
user2117821

Reputation: 25

EOL while scanning string literal when trying to print a \ in python

I'm trying to print just a \ using python and it seems like \ is some kind of reserved character or something. The code print "\" returns SyntaxError: EOL while scanning string literal. Any suggestions?

Upvotes: 1

Views: 2921

Answers (2)

pyrospade
pyrospade

Reputation: 8078

You can't end a string with a \ character since you could be asking it to escape the " character. You need to use "\\"

Upvotes: 0

user849425
user849425

Reputation:

The backslash is used in Python for escape sequences. The proper way to do what you want is:

print "\\" # You need to escape the \ character

Upvotes: 1

Related Questions