Python 3.11: What’s New?


Python is an open-source programming language. What makes Python open-source is that it is constantly been upgraded by the Python community. This is 2022 and this is the year of Python’s 3.11 version.

Python 3.11 is faster than Python 3.10

Python 3.11 can be up to 60% faster than Python 3.10. The benchmark suite runs up to 25% faster than in 3.10. This can be profitable to Python programmers and data scientists.

Exception Notes

Python 3.11 offers a new function called add_notes() to make the exceptions as expressive as possible. Any custom messages can be passed so that they will be displayed if any error will be raised.

More Expressive Error Messages

Python 3.11 has a new upgrade with the display of error messages. Previously, the interpreter would throw an error mentioning the line number and error description, but with this version, the ~ and ^ characters are added to specify where the error actually might be.

New Modules in Python 3.11

TOML Support The human-friendly and computer-friendly Tom’s Obvious Minimal Language has now been included in Python’s standard library tomllib. TOML provides metadata for projects and packages. wsgiref.types This module provides utilities for static type checking.

Upgradations to Standard Libraries

Most of the common and stand libraries of Python gone improved with Python 3.11.

typing : self

The function returning self-objects was a lot more confusing and almost impossible. But typing library in Python 3.11 includes a self that lets you return the instances of a class.

Typedict: Required and NotRequired

All the fields in the typedict used to be compulsory. But Python 3.11 introduces Required and NotRequired, which can mark if the item is mandatory or not.