Python SyntaxError: invalid syntax

Python Zac 2 years ago (2018-02-20) 1443 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:

Result:

SyntaxError: invalid syntax

 

Reason:

  • 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:

 

Result:

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

So the correct code is:

 

 

Like (5)
Comment
Cancel comment

emoji Image Bold Strilethrough Center Italic

Your email and address

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