Explore Courses Blog Tutorials Interview Questions
+1 vote
in Python by (47.6k points)

I'm using python 3.5.1. When I was trying this


I got the error: SyntaxError: EOL while scanning string literal. But this one worked well


Can anyone please explain this?

1 Answer

+1 vote
by (106k points)

In the first you are escaping your closing ', hence the SyntaxError you mention in your question is raised, because your string now never terminates. In the second you are escaping the final \ so the ' is not escaped. '\\' is a literal backslash rather than an escape, which is why the ' is not escaped in the second version, and why the '\' at the end of the first version is not escaped.

To know more about this you can have a look at the following video tutorial:-

Related questions

Browse Categories