Python SyntaxError: EOL While Scanning String Literal β How to Fix It
SyntaxError: EOL while scanning string literal
EOL means βEnd Of Line.β Python reached the end of a line while still inside a string β meaning you have an unclosed quote.
Fix 1: Close your quotes
# β Missing closing quote
message = "Hello world
# β
Close it
message = "Hello world"
Fix 2: Escape quotes inside strings
# β The quote inside breaks the string
message = "She said "hello""
# β
Use different quotes
message = 'She said "hello"'
# β
Or escape them
message = "She said \"hello\""
Fix 3: Use triple quotes for multiline strings
# β Regular strings can't span lines
message = "This is a
very long message"
# β
Use triple quotes
message = """This is a
very long message"""
# β
Or use backslash continuation
message = "This is a " \
"very long message"
Fix 4: Escape backslashes in file paths
# β \n is interpreted as newline, \U as unicode escape
path = "C:\Users\new_folder"
# β
Use raw string
path = r"C:\Users\new_folder"
# β
Or use forward slashes
path = "C:/Users/new_folder"
# β
Or escape the backslashes
path = "C:\\Users\\new_folder"
Fix 5: Check for invisible characters
Sometimes copy-pasting code introduces invisible characters or βsmart quotesβ (curly quotes from Word/Google Docs):
# β Smart quotes (look similar but aren't)
message = "hello" # These are curly quotes!
# β
Regular quotes
message = "hello"
If you suspect this, delete the quotes and retype them manually.
Related resources
Related: Python TypeError: Can Only Concatenate Str to Str β How to Fix It