Python Tutorial
About Lesson

In this Python tutorial we want to learn about Python 3.9 New Features with Examples, as you know python 3.9 was introduced in 5th October 2020, so there has been some new improvements on python language, from two new method of merge and update on dictionary class, introduction of new string methods and zoneinfo library up to a number of new features have been added. also a new stable and high-performing parser has been introduced in python 3.9. in this lesson we want to introduce some New Features in Python 3.9 with examples.

 

 

 

Dictionary Merge & Update Operators

Merge ( | ) and update ( |= ) operators have been added to the built-in dict class. Those complement the existing  dict.update and  {**d1, **d2} methods of merging dictionaries, now let’s create a simple example.

 

In here I have two dictionaries and i want to merge and update these two dictionaries, now first let’s do this without Python 3.9 operators.

 

 

 

If you run the code, you can see that the dictionaries are merged and updated.

Python 3.9 New Features with Examples
Python 3.9 New Features with Examples

 

 

 

Now let’s do this using Python 3.9 new operators of Merge (|) and update (|=).

 

And if you run the code we will receive the same result.

 

 

 

String Methods for Removing Prefix and Suffix

Two new string methods for removing prefixes and suffixes have been added.

 

 

 

If you run the code this is the result.

Python 3.9 New Features with Examples
Python 3.9 New Features with Examples

 

 

 

Type Hinting Generics in Standard Collections

In type annotations you can now use built-in collection types such as list and dict as generic types instead of importing the corresponding capitalized types (e.g. List or Dict) from typing.

 

Let’s first create an example before Python 3.9.

You can see in the above example we have imported List from typing, if we don’t do this we will receive error in our code.

 

 

So now let’s create our same example with Python 3.9.

You can see that in Python 3.9 we don’t need to import the List from typing.

 

 

 

Run the code and this is the result.

Python 3.9 Type Hinting
Python 3.9 Type Hinting

 

 

 

ZoneInfo Module 

zoneinfo module brings support for the IANA time zone database to the standard library. It adds zoneinfo.ZoneInfo, a concrete datetime.tzinfo implementation backed by the system’s time zone data. if you are using Mac or Linux you can use the zoneinfo directly, but if you are using window you to install a third party library that is called tzdata.

 

 

And this is the code.