Here are resources for changes introduced in Python recently:
Changing Python Versions
Changing Python Versions. Sometimes code that works perfectly fine in one version of Python breaks in a newer version. This is due to official changes in language syntax, the most well-known of which is the
This is one of the examples where the error message provided along with the
SyntaxError really does shine. Not only does it tell you that you’re missing parentheses in a
00:42 Another problem you might encounter is when you’re reading or learning about syntax that’s valid in a newer version of Python, but isn’t valid in the version you’re writing in. An example of this is the f-string syntax, which doesn’t exist in Python before version 3.6.
00:59 So here, running Python 2.7…
As you can see, in Python 2.7 the f-string syntax is not present and it just provides a generic
invalid syntax message. The problem, in this case, is the code looks perfectly fine but it was run with an older version of Python—2.7, in this case.
So when in doubt, double check which version of Python you’re running. Python 3.8 introduced
SyntaxWarning. You’ll see this warning in situations where the syntax is valid but it still looks suspicious.
An example of this would be if you were missing a comma between two tuples in a list. This would be valid syntax in Python versions before 3.8, but the code would still raise a
TypeError because a tuple is not callable.
The helpful message accompanying the new
SyntaxWarning even provides a hint,
perhaps you missed a comma, to point you in the right direction.
Become a Member to join the conversation.