SyntaxError: invalid character '“' (U+201C)
What it means
Your code contains a character that looks like normal punctuation but is not. Word processors, PDFs, chat apps and some websites swap straight quotes for curly ones and hyphens for dashes. Python only accepts the plain characters you type on a keyboard.
1. Curly quotes copied from a document
This raises the error
Traceback (most recent call last):
File "<exec>", line 1
print(“Hello, world”)
^
SyntaxError: invalid character '“' (U+201C)The fix
Hello, world
Python strings use straight quotes, " or '. Curly quotes, double or single (‘ ’), are not quotes to Python. Retype them in the editor instead of copying them.
2. A dash instead of a minus sign
This raises the error
Traceback (most recent call last):
File "<exec>", line 1
total = 10 – 3
^
SyntaxError: invalid character '–' (U+2013)The fix
7
Documents often turn a hyphen into a longer dash (U+2013). The minus sign Python understands is the plain hyphen key on your keyboard.
3. Invisible non-breaking spaces from a web page
This raises the error
Traceback (most recent call last):
File "<exec>", line 3
print(p)
^
SyntaxError: invalid non-printable character U+00A0The fix
4 7 2
Some web pages use non-breaking spaces, which look exactly like normal spaces. Python reports them as invalid non-printable character U+00A0. Delete the indent and retype it with the space bar.
When you see this error, check
- Read the character and its
U+code in the message to know exactly what to replace. - Retype quotes, dashes and spaces near the caret instead of copying them.
- Copy code from code blocks, not from the formatted text around them.
- Turn off smart quotes in any notes app where you keep code.
Related errors
All Python errors · How to read a traceback · Step through your code