Python 3.10-Two new features which you should know about
On 4th October the new version of python was released i.e., Python 3.10 and as a python enthusiast, I am excited to talk about some features which I found very useful.
1. Updated error messages: This is a great help for all the beginners out there, the previous error messages provided in python were not descriptive and it didn’t give much idea on how to rectify the same but with the new update, the error messages are much more descriptive with proper line reference.
This helps programmers like me from spending hours in finding what the error is, sometimes it is just a colon or a comma which is really frustrating.
Some of the examples are provided below (Version – 3.8.3 comparison):
Indentation and Syntax Error: As you can see below, in the first image the error message is not descriptive but in python 3.10 the type of the error and where the error occurs is also mentioned.
In the below example a colon was missing after the if statement and as you notice the previous version just provided us with the information that it’s a syntax error but the newer version is much more efficient as it tells us where the error is and what should be provided in that place.
Recommended by LinkedIn
2. Structural pattern mapping or use of match and case statements:
Java, C++ and many other programs had the function of case statement where static value is provided and based on the conditions the operations were performed. Now with the new update we have the match and case statement.
In the example above, we have created a match and case statement in a function where if a particular number is selected then the case assigned to it is returned. In the last case statement, we have a wildcard where if a number other than specified cases are selected then the wildcard case is returned.
There are numerous other updates and for your curiosity I have provided the link to the documentation below: