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.