logo
logo
Sign in

A Quick Look at the Best New Features in Python 3

avatar
Tiffany Harper
A Quick Look at the Best New Features in Python 3

The new Python 3.9 version comes with several features that make it an exciting one to look out for. The performance boosts to the faster release schedule, stable and consistent internal APIs, and dictionary union operators are some fascinating features of Python 3.9. So, what are those things that we can easily point out in Python 3.9?

Python now uses a different yearly release cycle 

Before now, Python usually took up to eighteen months before they released new versions of their product. But after a proposal was made by PEP 602 for the development team to adopt a yearly release cycle, it is something that has now been adopted.

Using a yearly release cycle implies that there will be fewer features in each release. However, it also means that users will get faster feedback on their feature testing. Each release will have very few potentially breaking changes. There will be more incentive for Linux distribution managers and other users to upgrade their Python more regularly. This also implies that new features proposed at the later stages of the development cycle wouldn’t take much time before they are included in a news release. 

Python is much faster by default 

Every time that Python is revised, there are usually some performance improvements from the last one. With Python 3.9, two significant improvements boost its performance without making any changes to the present code

The first improvement that they made was using the vector call protocol, which they introduced in the Python 3.8 version. This vector call protocol eliminates temporary objects created for a call, thereby making it possible for other common functions to call faster. But in Python 3.9, there are several Python built-ins, such as frozen set, set, list, range, diet, tuple, which speeds up execution by using the vector call internally. 

The second improvement in performance enhancement is increasing the efficiency of the Python source code. However, the new parser they created for C Python runtime was not intended to address performances. Instead, it was meant to deal with the little internal inconsistencies that may exist with the original parser. However, this comes with the extra benefit of making parsing faster, especially if it is for a large number or volume of codes. 

More dictionary functions and Python strings 

With the skills in Python generally, it is easy to manipulate the different types of common data. But with Python 3.9, it is even easier to extend the ease as it has new features that work for the dictionaries and strings. 

For the strings, new ways of removing and dealing with prefixes and suffixes are introduced. These are operations that would typically require some manual work to accomplish. For dictionaries as well, Python now has union operators. One of them is for merging two dictionaries into just one new dictionary, while the other one is to use one dictionary for updating the content of the other dictionary. 

For getting the best content you can find some here:

New types of Python operations

The last few Python versions have seen an increase in the help of type hinting. The reason for this is mainly because of code checkers and linters. There is no enforcement of types in CPython’s runtime, and there are also no plans for making Python a statically typed language. However, with type hinting, it’s a powerful tool for ensuring that the large codebases have some consistency level. This will also ensure that Python codes continue to benefit from the fact that they still have type hints. 

Two new features are introduced for type annotations and type hinting in the Python 3.9 version. In one of the features, type hints for collections contents, such as dictionaries and lists, are now natively present in Python. This means that it is possible to now describe a list of integers, for instance, without requiring that the typing library does it. 

The second feature added to Python’s typing mechanism is the variable annotations and flexible function. With this feature, the ‘Annotated’ type will be able to use the metadata to describe a possible type to examine at runtime or before time (using the linting tools). For example, Annotated[int, type (“char”)] can be used for describing an integer, which should also be considered as a type of ‘char’ in C. The code linters can actually use this type of annotation. However, Python, by default, would not do anything with an annotation like this. 

Improvements to the internals of Python 

Modernizing, refining, and cleaning up the internals of Python is an initiative that is very much still in process for the developers of Python. And in the same vein, Python 3.9 comes with some changes to this. 

The first change is to redesign the way that the modules and the import machinery interact. The Python extension modules, which they usually write in C, can now use a totally different and brand-new loading mechanism which makes them act a lot like the standard Python modules when they imported them. There are several modules in the standard library of Python that are now supporting this behavior. Some of them are JSON, functions, bz2, audio, abs, resource, time, codecs, crypt, context vars, operator, locale, and weakref. Apart from allowing flexibility in the way that the extension modules are handled, this new loading mechanism at the same time enables other new capabilities like advanced hooking behaviors. 

Another cleanup initiative that they recently introduced for C Python is the stable internal ABI. This is guaranteed to last the whole lifespan of Python 3. Taking cues from the past, every major revision that Python does usually has not been ABI compatible with the past versions. It would typically require that the extension modules be recompiled for all new versions. But this has changed now, and all extension modules using the stable ABI will now work across the different versions of Python from now on. In the new version, Python 3.9, some modules are already using the stable ABI in the standard library. These modules are audio, Z lib, termios, grp, ast, struct, PWD, _posixsubprocess, select, and random.  

New parser 

The new parser is one of the most interesting features of Python 3, and it has a massive potential to become that change that is the most significant and reshapes the evolution of Python going into the future. 

As of now, Python uses the LL(1)-based grammar, and consequently, the LL(1) parser – that passes the code from left to right, up-down - can parse it with a token look ahead. This method, however, does have a few issues that it causes in Python such as

  • The current grammar has some parts using the LL(1) grammar, which tends to create unnecessary complexities. 
  • Without possible workarounds, the LL(1) also create Python syntax limitations. This means that you cannot implement some codes because of the parser. 

These factors tend to limit how Python as a language evolves. But the new parser, which is based on the PEG, will make it possible for the developers of Python to be a lot more flexible. 

Conclusion 

There is no doubt at all that the Python 3.9 is an improvement on the previous Python version, as their custom is anyway. But you can see it that the improvements are massive, and this might as well be the most important version yet as it is likely to determine the future of Python going forward. 

Summary 

The Python 3.9 version has numerous features that massively improve it from the last version. 



collect
0
avatar
Tiffany Harper
guide
Zupyak is the world’s largest content marketing community, with over 400 000 members and 3 million articles. Explore and get your content discovered.
Read more