Problem
A Python script fails to execute and raises the following exception:
SyntaxError: invalid syntax
The error occurs on a line containing an assignment statement or expression that uses what appears to be an equal sign (=).
Cause
The most likely cause is that the character used as the assignment operator is not the standard ASCII equals sign (=) recognized by Python.
This can happen when:
- Code is copied from formatted documents, web pages, or messaging applications.
- A Unicode character that visually resembles
=is inserted accidentally. - Text is entered using an incorrect keyboard layout or input method.
- An editor automatically replaces standard characters with typographic alternatives.
Although the character may look identical to =, Python interprets it as a different symbol and reports a syntax error.
Resolution
Re-enter the problematic line of code manually to ensure no hidden or non-standard characters are present. Verify the keyboard layout is set correctly to prevent the substitution of invalid or unexpected characters.
Comments
0 comments
Please sign in to leave a comment.