Warning

This documentation needs to, and is about to be updated significantly.

Comparison between Python versions

In this file, we highlight differences between the information given by different versions of Python when it comes to SyntaxError. The content of this file is likely of no use to anyone except for people who write code to include new SyntaxError cases.

The differences between Python versions can be:

  1. The error message itself.

  2. The location of the error as indicated by Python with ^. We’ve decided to leave these out for now.

As a consequence, the information as to what we guess is the cause can be slightly different. So, we also show when we assign a different cause.

Note that the content below is extracted automaticaly by a simple program we wrote for this purpose. If the information is the same for Python 3.6 and 3.7, but changes for Python 3.8, we only show the differences between 3.7 and 3.8.

raise_syntax_error10
3.7: SyntaxError: can't assign to literal

3.8: SyntaxError: cannot assign to literal

raise_syntax_error13
3.7: SyntaxError: can't assign to keyword

3.8: SyntaxError: cannot assign to None

raise_syntax_error14
3.7: SyntaxError: assignment to keyword

3.8: SyntaxError: cannot assign to __debug__

raise_syntax_error15
3.7: SyntaxError: invalid syntax

3.8: SyntaxError: unmatched ')'

3.7: I make an effort below to guess what caused the problem
but I might guess incorrectly.

The closing parenthesis ')' on line 6 does not match anything.

    6:     3, 4,))
                 ^

3.8: The closing parenthesis ')' on line 6 does not match anything.

raise_syntax_error18
3.7: SyntaxError: invalid syntax

3.8: SyntaxError: closing parenthesis ']' does not match opening parenthesis '('

3.7: I make an effort below to guess what caused the problem
but I might guess incorrectly.

The closing square bracket ']' on line 2 does not match the opening parenthesis '(' on line 2.

    2: x = (1, 2, 3]
           ^       ^

3.8: Python tells us that the closing ']' on the last line shown
does not match the opening '('.

I will attempt to be give a bit more information.

The closing square bracket ']' on line 2 does not match the opening parenthesis '(' on line 2.

    2: x = (1, 2, 3]
           ^       ^

raise_syntax_error19
3.7: SyntaxError: invalid syntax

3.8: SyntaxError: closing parenthesis ']' does not match opening parenthesis '(' on line 2

3.7: I make an effort below to guess what caused the problem
but I might guess incorrectly.

The closing square bracket ']' on line 4 does not match the opening parenthesis '(' on line 2.

    2: x = (1,
           ^
    4:      3]
             ^

3.8: Python tells us that the closing ']' on the last line shown
does not match the opening '(' on line 2.

I will attempt to be give a bit more information.

The closing square bracket ']' on line 4 does not match the opening parenthesis '(' on line 2.

    2: x = (1,
           ^
    4:      3]
             ^

raise_syntax_error30
3.7: SyntaxError: can't assign to function call

3.8: SyntaxError: cannot assign to function call

raise_syntax_error31
3.7: SyntaxError: can't assign to function call

3.8: SyntaxError: cannot assign to function call

raise_syntax_error41
3.7: SyntaxError: keyword can't be an expression

3.8: SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

3.7: You likely called a function with a named argument:

   a_function(invalid=something)

where 'invalid' is not a valid variable name in Python
either because it starts with a number, or is a string,
or contains a period, etc.


3.8: One of the following two possibilities could be the cause:
1. You meant to do a comparison with == and wrote = instead.
2. You called a function with a named argument:

       a_function(invalid=something)

where 'invalid' is not a valid variable name in Python
either because it starts with a number, or is a string,
or contains a period, etc.


raise_syntax_error42
3.8: SyntaxError: invalid character in identifier

3.9: SyntaxError: invalid character '🤖' (U+1F916)

raise_syntax_error47
3.7: SyntaxError: can't delete function call

3.8: SyntaxError: cannot delete function call

raise_syntax_error52
3.7: SyntaxError: can't assign to literal

3.8: SyntaxError: cannot assign to set display

raise_syntax_error53
3.7: SyntaxError: can't assign to literal

3.8: SyntaxError: cannot assign to dict display

raise_syntax_error54
3.7: SyntaxError: can't assign to literal

3.8: SyntaxError: cannot assign to literal

raise_syntax_error55
3.7: SyntaxError: invalid syntax

3.8: SyntaxError: cannot use assignment expressions with True

3.6: I make an effort below to guess what caused the problem
but I might guess incorrectly.

You appear to be using the operator :=, sometimes called
the walrus operator. This operator requires the use of
Python 3.8 or newer. You are using version 3.6.

3.7: I make an effort below to guess what caused the problem
but I might guess incorrectly.

You appear to be using the operator :=, sometimes called
the walrus operator. This operator requires the use of
Python 3.8 or newer. You are using version 3.7.

3.8: True is a constant in Python; you cannot assign it a value.


raise_syntax_error56
3.7: SyntaxError: can't assign to operator

3.8: SyntaxError: cannot assign to operator

raise_syntax_error58
3.7: SyntaxError: can't assign to generator expression

3.8: SyntaxError: cannot assign to generator expression

raise_syntax_error59
3.7: SyntaxError: can't assign to conditional expression

3.8: SyntaxError: cannot assign to conditional expression

raise_syntax_error65
3.8: SyntaxError: keyword argument repeated

3.9: SyntaxError: keyword argument repeated: ad

raise_syntax_error66
3.8: SyntaxError: unexpected EOF while parsing

3.9: IndentationError: expected an indented block

3.8: Python tells us that it reached the end of the file
and expected more content.


3.9: In this case, the line identified above
was expected to begin a new indented block.

raise_syntax_error9
3.7: SyntaxError: can't assign to literal

3.8: SyntaxError: cannot assign to literal

entry does not exist in one data file for raise_syntax_error_walrus