Python 3.9 : What’s New Now? Cool Features To Checkout

Python is an all-time favorite and most favored language among developers. According to The Tiobe index which is a programming community that ranks programming languages according to their popularity, Python has been ranked second overtaking Java. Python has excellent community support and due to its simplicity and easy to use nature, every beginner aspires to master at least this language.

While this language has grasped a lot of eyeballs in recent years finding its usage in the field of data analytics, machine learning, web development, computer application, IOT or other development areas, its latest version Python 3.9 stable has been released and it brings a lot of changes from the parser to additional functionalities to change in the feature releases timeline. Let’s look at these changes in detail:

New Operator

While dealing with dictionaries, it is very often that we need to merge or update them with entries from other dictionaries. Earlier this could be done using the update attribute of dictionary object: first_dict.update(second_dict) but the problem with this approach is that the changes are done in-place, and original values are modified.

To make it a temporary change, another variable is required to store the previous value. This new version has introduced a new operator known as a merge operator (|) which can be used to merge dictionaries. Here is a code example to understand this:

A = { “name” : “Author”, “company” : “upGrad”}

B = { “status” : “instructor”}

print (A|B)

Output:  { “name” : “Author”, “company” : “upGrad”,  “status” : “instructor”}

| is like a concatenation operator but if you want to update the original value then you can simply use the |= operator. Continuing the previous example, A |=B will update the value of A dictionary. 

Also read: Python Developer Salary in India

String Operations

Text manipulation forms a major part of the data science lifecycle, especially during NLP. There are different functions to perform different types of string operations such as splitting, concatenation, replacement, and many more. Joining this legacy, two new operations have been added which are removesuffix() and removeprefix().

As the name suggests, these are used to remove prefixes and suffixes from a string. They are accessible by using the string object. This removal could be easily done using regular expressions and slicing of the strings but now we have this functionality in built-in libraries. Here is a simple example for illustration purpose:






Modified Timezone Module

This version has also introduced a new module named zone info supporting the IANA database in the standard library. We can specify the timezone in the DateTime object from the standard library but the user can end up creating complex rules for the time zones. As per PEP 615, the userbase is more inclined towards major time zones such as UTC, IANA, or system local time zone. Now you can create a zone info object by specifying the config search path which is of the form “continent/city”. For instance,

from zoneinfo import ZoneInfo

from datetime import datetime

dt = datetime(2020, 11, 15, 01, tzinfo=ZoneInfo(“Asia/Kolkata”))


Output: ‘IST’

Learn about: Top Python tools

New Math Functions

The math module consists of all numerical operations that are used in general mathematics. Whether it’s sine, cosine functions, rounding off numbers to specific places, or universal constants such as pi or exponential, the math module covers almost all types of functions.

Three new functions have been added to this list and there is math.lcm(), math.nextafter(), math.ulp(). While the LCM (Least Common Multiple) is a very commonly used function, the other two are not used as much. Earlier, we had to explicitly create a function for LCM operation but now starting this new version, we have a built-in functionality in the standard library. To use this function simply call:

import math


Output: 6

If no arguments are passed in this function then it returns 1 and if one of them is zero then it returns 0.

High-Performance Parser

Apart from all the new additions on the feature level, the Python language parser is also updated to new, faster technology known as PEG parser. This effect will not reflect in this version but the upcoming Python 3.10. From the day Python was created, it has been using LL(1) parser which parses the code from top to bottom and left to right. This parser is based on context-free grammar and therefore it is ambiguous meaning that the strings can have more than one parse tree and increasing the number of intermediate steps. The new PEG parser generates only one valid AST (Abstract Syntax Trees) removing the ambiguity of the previous parser. 

New Random Function and Change in Release Cycle

In the random.random module, new method randbytes(n) has been added which returns random n bytes. It is very similar to other random functions. Also previously, Python releases a new version every 18 months which has been reduced to 12 months.


Whenever a new version of software releases, it accompanies a lot of new changes. Here we have discussed some of the major and highlighted changes in Python which include new operator, added features, and improved parser.

There are a lot of new changes in other modules also such as ast, asyncio, concurrent.futures, multiprocessing, XML. Some functions have been depreciated and the list goes on. You can check the official documentation for a full list of updates in the new Python 3.9. 

If you are curious to learn about python, data science, check out IIIT-B & upGrad’s PG Diploma in Data Science which is created for working professionals and offers 10+ case studies & projects, practical hands-on workshops, mentorship with industry experts, 1-on-1 with industry mentors, 400+ hours of learning and job assistance with top firms.

Prepare for a Career of the Future

Learn More

Leave a comment

Your email address will not be published. Required fields are marked *