Python SyntaxError: invalid syntax

Python Zac 3 years ago (2018-02-20) 1928 views 0 comments

The first example:

If you are new in Python, it is very easy to ignore some necessary signs in your Python code.

It is normal to occurred SyntaxError: invalid syntax.

This is the first example:


SyntaxError: invalid syntax



  • The equal sign(=) is used to assign a value to a value. But look at the second line, it should ues(==), not (=).
  • The sign(==) is a  comparison operator, it likes (<) and (>).


So in this example, the correct code is:


The second example:



Reason: You should add the sign(:) in the end of “if, elif, else, for, while, class, def”.

So the correct code is:



Like (5)
Cancel comment

emoji Image Bold Strilethrough Center Italic

Your email and address

  • Name (Required)
  • Email (Required)
  • Website(Optional)