TryBugHunt

SyntaxError: invalid character '“' (U+201C)

SyntaxError: invalid character '“' (U+201C) in Python means your code contains a "smart" character that looks like normal code but is not. Usually curly quotes copied from WhatsApp, Word, a PDF or a website.

Python

How do I fix SyntaxError: invalid character '“' (U+201C)?

SyntaxError: invalid character '“' (U+201C) means your code contains a curly quote instead of a straight one. It usually comes from copying code out of a chat app, Word, a PDF or a phone keyboard with smart punctuation. Delete the curly quotes on that line and retype them as plain " or ' from your keyboard.

  1. 1. Read the U+ codeU+201C and U+201D are curly double quotes, U+2018 and U+2019 curly single quotes, U+2013 an en dash.
  2. 2. Retype the charactersDelete every quote and dash on the reported line and type them again in a code editor.
  3. 3. Turn off smart punctuationOn a phone, disable smart quotes in keyboard settings. Copy code from code blocks, not from normal text.

What does SyntaxError: invalid character '“' (U+201C) mean?

Python only accepts plain straight quotes " and ' around strings. Many apps change them to curly quotes “ ” ‘ ’ to look nicer, and phone keyboards often do it as you type. U+201C is the code for the left curly quote “. The same error appears for a long dash – (U+2013) instead of a minus sign. Older Python versions say "invalid character in identifier".

Why does SyntaxError: invalid character '“' (U+201C) happen?

1. Curly double quotes

Copied from a chat, document or slide. They look like quotes, but Python sees unknown symbols.

Breaks

print(“Hello”)

Works

print("Hello")

2. Curly single quotes

Same problem with ‘ and ’ (U+2018 and U+2019).

Breaks

name = ‘Ada’

Works

name = 'Ada'

3. A dash instead of a minus

Word processors turn - into – or —. Python needs the plain hyphen-minus key.

Breaks

x = 5 – 2

Works

x = 5 - 2

How to find it in your own code

Checklist: 1) Look at the character in the message and the line number. 2) Delete each quote or dash on that line and retype it with your keyboard. 3) On a phone, turn off "smart punctuation" or "smart quotes" in keyboard settings, or use the code editor's symbol bar. 4) When copying code, copy from a code block, not from normal text, and paste into a code editor rather than a notes app.

Still not sure why yours breaks?

Paste it into the visualizer and watch it run line by line, with every variable at every step. Free, and it runs in your browser.

Related error guides