Python 3.12 official version has been launched, improving many existing features, including f-string parsing improvements, Buffer Protocol (Buffer Protocol), etc., but also improved the error message, so that developers can be more clear about the reasons for the error, in addition, the development team has also carried out a series of performance improvements, claiming that In addition, the development team has made a number of performance improvements, claiming that “the overall performance of this release has been improved by about 5%.”
▲ Source Python website
In Python 3.12, f-string parsing is said to be more flexible, and many previously disallowed operations are further relaxed in this version.
In 3.11, f-string expressions that reused the same quotes as an external f-string would result in a syntax error, which is now allowed in 3.12; in the previous version, f-string expressions themselves could span multiple lines, but still had to be defined on a single line, whereas in 3.12 developers can use multi-line expressions. Previously, the f-string could not contain any backslash symbols “\”, which are now allowed in the new version, so the f-string can now also contain Escape Sequences.
Python developers in the new version can more easily use Buffer Protocol (Buffer Protocol), which is a lightweight and efficient structured data storage format, when dealing with a large number of data files, the use of related protocols, can improve performance and save storage space.
Python 3.12 introduces a new approach to address the problem of the Buffer Protocol, which has been used primarily in Python’s C API and has not been friendly to Python-only developers, allowing developers to manipulate the functionality more directly in Python, rather than through C or other methods.
Python 3.12 also improves error messages, making it easier to identify the cause of an error and to fix it. When a developer incorrectly uses the import syntax, the correct usage is suggested, and when an instance property is used in a category method that is not referenced correctly, the error message now points to the correct property name in the project itself.
Python 3.12 also features a number of performance improvements. Unicode has been streamlined in this release to make it lighter and less space-intensive, and Python uses the BOLT binary tool to improve performance in scenarios by 1 to 5% when building environments.