Editor

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

Broken
print(“Hello, world”)
Output
Traceback (most recent call last):
  File "<exec>", line 1
    print(“Hello, world”)
          ^
SyntaxError: invalid character '“' (U+201C)

The fix

Fixed
print("Hello, world")
Output
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.

Try fixing it yourself in the editor

2. A dash instead of a minus sign

This raises the error

Broken
total = 10 – 3
print(total)
Output
Traceback (most recent call last):
  File "<exec>", line 1
    total = 10 – 3
               ^
SyntaxError: invalid character '–' (U+2013)

The fix

Fixed
total = 10 - 3
print(total)
Output
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.

Try fixing it yourself in the editor

3. Invisible non-breaking spaces from a web page

This raises the error

Broken
prices = [4, 7, 2]
for p in prices:
    print(p)
Output
Traceback (most recent call last):
  File "<exec>", line 3
        print(p)
    ^
SyntaxError: invalid non-printable character U+00A0

The fix

Fixed
prices = [4, 7, 2]
for p in prices:
print(p)
Output
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.

Try fixing it yourself in the editor

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.

All Python errors · How to read a traceback · Step through your code