What's New In Python 3.9

Python 3.9.0b3 is released with some exciting new features. Check out what is stored in the released preview version.

Python 3.9 development is still under progress. However, you can download the latest version Python 3.9.0b3 from the official link. You can expect two more beta release versions in the coming days because this new release is the third of the five planned beta release preview versions.

The Python officials recommend to use & test this preview version and report any issues(if found) on the official site. This bug reporting will help the Python team to release a stable and bug-free version at the earliest.

New Features in Python 3.9

A brief about Python:


Python is an interpreted, object-oriented programming language developed by Guido van Rossum. It was released with the prime focus on the foreground of code readability, specifically by using significant whitespaces. It is an incredible language used for building both small as well as large scale applications. You can call us for any discussion about your Python project or refer to our in-depth guide on Python app development.

New Features in Python 3.9

Now let’s discuss the intriguing features of Python 3.9.0b3 in the next section.


Dictionary merge and union operators:

Merge (│) and Update (│=) have been introduced in the built-in dict class. Suppose you have two dictionaries a and b, then you can either merge or update them depending on the output you wish by using the operators mentioned above.

a = {1: “apple”, 2: “banana”}
b = {3: “mango”}
You can merge both the dictionaries by introducing the following line of command.

c= a│b
Print (c)
The output will be {1: “apple,” 2: “banana,” 3: “mango”}

When the dictionaries have a common key, the second dictionary’s value will appear in the output.

Now, for updating the dictionary, you can use Update (│=) operator.

a = {1: “apple”, 2: “banana”}
b = {3: “mango”}
a│=b
Print (a)
The output will be {1: “apple”, 2: “mango”}

Type Hinting:

As we know, Python is dynamically typed, meaning, we do not have to mention datatypes in the code. This becomes a bit of a hassle, and for static allocation, Type Hint is used. You are free to use built-in collection types (list and dict) as generic types. Earlier, you were required to import the capital types (List or Dict) from typing, which is no more required now.

def greet_all(names: list[str]) -> None:
for name in names:
print("Hello", name)

removeprefix() and removesuffix() String Methods:

This update can be useful in removing prefix or suffix in the methods. These updates have been added to Python’s Str class. Say for example,

Suppose you wish to remove the prefix, then type,

“Incredible python”. removeprefix(“In”)

The output will be: “credible python”
In the same way, if you wish to remove the suffix, then type,

“Incredible Python”. removesuffix(“on”)
The output will be: “Incredible Pyth”

Note: If the String doesn’t have the mentioned prefix or suffix, then the original string will appear as an output.

New Parser:

This update is sighted as the one which can bring revolution in the Python world. Python currently is based on LL(1) grammar, but now will use a PEG parser which is more flexible than LL(1). This new parser will analyze the code top to down, left to right by using just one token.

Few issues with the current LL(1) grammar parse are:

Some parts of the current grammar use workarounds, leading to needless complexities.

Also, LL(1) imparts some limitations. It doesn’t allow the following code to be implemented in the current parser.

with (open("a_really_long_foo") as foo,
open("a_really_long_bar") as bar):
pass

LL(1) breaks with left-recursion in the parser.

Hence, it was necessary for the Python team to bring Python 3.9 changes in the current grammar parser.

The new update Python 3.9 features introduce new libraries in the update.

zoneinfo:

This module will bring support for the IANA timezone database to the standard library. The example is listed below. You can find the same on the official site.

>>> from zoneinfo import ZoneInfo
>>> from datetime import datetime, timedelta
>>> # Daylight saving time
>>> dt = datetime(2020, 10, 31, 12, tzinfo=ZoneInfo("America/Los_Angeles"))
>>> print(dt)
2020-10-31 12:00:00-07:00
>>> dt.tzname()
'PDT'

>>> # Standard time
>>> dt += timedelta(days=7)
>>> print(dt)
2020-11-07 12:00:00-08:00
>>> print(dt.tzname())
PST

graphlib:

In order to perform the functionality of the topological sorting of graphs, you can use graphlib, which contains graphlib.TopologicalSorter class.

The following list of existing modules has also been improved, which is new in Python 3.9.0b3 version.

1. ast;

2. asyncio;

3. compelieall;

4. concurrent.futures;

5. curses;

6. datetime;

7. distutils;

8. fcntl;

9. ftplib;

10. gc;

11. hashlib;

12. http;

13. impalib;

14. importlib;

15. inspect;

16. And many more.

There is much depreciation also from the list, which you can refer to in the official document.

Conclusion:


So that is it in the new features of Python 3.9 update. We eagerly wait for the stable release in the coming months. Keep checking this section for new updates and releases. We keep a sharp eye and have a keen interest in providing you the latest updates and news. You can also hire our python developers for any of your future projects. We are a team of experienced professionals having in-depth knowledge about the technology.


ABOUT THE AUTHOR
blog Author - kodytechnolab

Mihir Mistry

CEO


RELATED POSTS