New Features in Python 3.10
Better Error Messages
The newest version of python (3.10), the error messages shown has been significantly improved. If you have been using the older version of python for a while, I am sure that you have noticed the weird messages being thrown by python in response to some errors. For example, when writing python code that requires an opening and a closing parentheses or brackets, if the bracket or parentheses is missing, python locates the particular line of code and tells you exactly what is missing, instead of just showing "SyntaxError: unexpected EOF while parsing". In the image below, you will notice that on line 14, the list is supposed to be closed with a "}"
when this code is executed with python 3.9 or older, it shows the error message below
In the image above, you will see that it says "SyntaxError: invalid syntax". That error message is correct, but it's not detailed, and it does not point to the line where the real error comes from. But if the code is executed with python 3.10, it shows this message
As you can see in the image above, the error message shows the specific line the error comes from, and it shows what causes the error.
Another feature that was added in the error messages section is name suggestions. Let's take the code in the image below as an example:
You will notice that in the image above, the variable is written as "name" instead of names. If this is executed with the older version of python, it will throw this error
But if it is executed with python 3.10, it will show this error
You can see in the image above that it did not just only say that "'name' is not defined", but it also suggests for the name of variable i was trying to print.
But, there is a new feature which will allow the program to automatically check the length of the two lists before trying to combine them together. The image below shows how to do this using the "strict" keyword:
Post a Comment
2 Comments
nice!
ReplyDeleteThanks
ReplyDelete