Skip to content

What does the 'EOL' stand for in 'SyntaxError: EOL while scanning string literal'

erikkristoferanderson profile image Erik Kristofer Anderson twitter logo github logo ・1 min read

I'm playing a game where I break my code and study the errors. I got this idea from "Learn Python the Hard Way." I know why I got the error: I deleted the quotation at the end of a string. What I don't know is what EOL stands for. I assume it stands for something? A cursory googling just brought up obscure examples of people being surprised to get this error.
And while we're at it, what does 'literal' mean in this context?

If you're curious, here's the broken code:

do_not = "don't
twitter logo DISCUSS (6)
markdown guide

It stands for End of Line. Here, it means that it was expecting to find a matching quotation, but instead hit the End of the Line without finding a match, which was unexpected.

Literal means you've got a literal representation of this string, i.e. the string itself in quotes. An array literal might be something like [1,2,3,4,5] - it's a bit of text that corresponds directly to the data type it represents.

Edit: the reason this syntax error comes out that way is because of the literal, actually. Though to a human the syntax error is that your quote isn't matched, what the parser was doing was attempting to read in a string literal to build its internal in-memory representation of a String from it. This isn't a multi-line string, so as it was reading in (scanning) the literal one token at a time, it ran into the end of a line. That's illegal in a string literal, thus this syntax error. Of course, the fix is to add the quote, which means the parser successfully reads the whole string literal and then moves on to the end of the line, where it now occurs in a valid, expected place.


I like this idea, intentionally breaking working code. You can learn a lot about how your language works from understanding why specifically you're getting a given error. Thanks for the tip!

Cool. I got the idea from "Learn Python the Hard Way' and I'm definitely going to continue using it.

Classic DEV Post from Aug 4 '19

You're not worth hiring unless...

Erik Kristofer Anderson profile image
Former Chemist , Current Student , Future Data Engineer