What’s new in Python 3.9

Finally Python 3.9 is out with some amazing features, taken a big leap from version 3.8 and have provided great new features to the programmer. Most of Python Programmers have been really excited about this new release and have been waiting for quite a long period of time. The following paragraphs provide detailed explanation about these features –

1) Updating and Merging Operator for Dictionary

  • What’s new

Two operators have been added to dict class, which provides very useful Dictionary object.

| operator for merging two dictionaries together

|= operator for updating dictionary

  • Using new features

The main point to be noted here is that if a key occurs in both of a, b dictionaries then only key-value which is in second dictionary would be in final dictionary. “Thus order in which operator is applied to dictionaries really matters.” This is clearly visible from above examples.

Interested in learning how this feature actually became a part of Python then check out here – https://www.python.org/dev/peps/pep-0584/

2) Removing prefix and suffix using new String Functions

  • What’s new

Two new functions have been added removeprefix and removesuffix which can be used for removing prefix, suffix respectively from a string.

  • Using new feature

Interested in learning how this feature actually became a part of Python then check out here – https://www.python.org/dev/peps/pep-0616/

3) Hinting types for built-in generic types

Annotating programs have been made simpler in this release by removing the parallel type hierarchy in Python. The release has enabled support for the generics syntax in all standard collections currently available in the typing module. We can use the list or dict built-in collection types as generic types instead of using the typing.List or typing.Dict in the signature of our function. Therefore, the code now looks cleaner and it has made it easier to understand/explain the code.

4) Cancelling concurrent futures

A new parameter cancel_futures have been added to the concurrent.futures.Executor.shutdown().This parameter cancels all of the pending futures that have not started. Prior to version 3.9, the process would wait for them to complete before shutting down the executor. The new parameter cancel_futures have been added to both ThreadPoolExecutor and ProcessPoolExecutor. The way it works is when the value of the parameter is True then all pending futures would be canceled when the shutdown() function is called. In a nutshell, when the shutdown() is executed, the interpreter checks if the executor is not garbage collected. If it is still in memory then it gets all of the pending worker items and then cancels the futures. Once there are no pending work items then it shuts down the worker.


Interested in learning Python Programming Language. It would be definitely worth it check following book, this book have helped me to improve my programming skills a lot over my journey in becoming expert Python Developer.

These are just some of the new features added to Python3.9 interested in knowing all of new features added to the language check out following articles –

https://docs.python.org/3.9/whatsnew/3.9.html

https://towardsdatascience.com/10-awesome-python-3-9-features-b8c27f5eba5c

Josh

Hi, I'm Josh a Computer Science graduate from California State University, Sacramento since coming out with my Master's from university. I've worked with multiple startups across US and in UK as well primarily as a Python Developer. Here on this website, I'm sharing my knowledge of Python. If you want to ask me anything about Python feel free to reach out, I would be happy to help you out.

Recent Posts