A new version of Python is coming! Soon, it will be on our machines. Python has released a beta version of Python 3.9 (3.9.0b3) and will release the full version of Python 3.9 soon.

The new version introduces some exciting features and new modules. It will be interesting to do a hands-on exercise with them. Till then, let’s learn about the functionalities of those features and modules.

Introducing New Features

Dictionary merge and update operators

Python 3.9 introduces merge(|) and update(|=) operators in the dict class. If you have two dictionaries x and **y, **you can now use these operators to do merge and update them.

x = {1: "one", 2: "two"}
y = {3: "three"}

You can use | to merge these both dictionaries.

z=x|y
print(z)

[Output]: {1: "one", 2: "two", 3: "three"}

If both the dictionaries have a common key, then the output will display the second key-value pair.

x = {1: "one", 2: "two",3: "3"}
y = {3: "three"}

z=x|y
print(z)
[Output]: {1: "one", 2: "two", 3: "three"}

For updating the dictionary, you can use the following operator.

x = {1: "one", 2: "three"}
y = {2: "two"}
x|=y
print(x)
[Output]: {1: "one", 2: "two"}

#python #developer

Python 3.9 Is Bringing Some Exciting New Features
2.95 GEEK