Python has been developed initially in 1991 and since then it has gradually evolved into the version 3.x. Most of us used python 2.7.x for a long time for different projects which is now came to the end of his lifecycle from 2020 onwards.

In the most recent release of python version 3.8, it has incorporated a set of kool features as an advancement. We will discuss a few of them below.

Robust Function Arguments types:

Python supports both Positional and Keyword arguments for a long-time already. But in there recent release they have added flexibility for a single argument can be defined either as positional or keyword argument using syntax / and *. Example as follows:

def test_func(a, /, b, c, *, d, e):
return a + b + c + d + e

test_func(1, 2, 3, 4, 5) # Error: invalid as "d" and "e" are keyword-only
test_func(a=1, b=2, 3, d=4, e=5) # Error: invalid as "a" is position-only test_func(1, 2, c=3, d=4, e=5) # Success: 15
test_func(1, b=2, c=3, d=4, e=5) # Success: 15

Reversible dictionary:

In Python, dictionary is an unordered collection of data to store values like a map(as key:value pair). Keys of a dictionary must be unique and of immutable data type such as strings, integers etc. Previously, we were unable to reverse the dictionary with built-in functions but with python 3.8 it’s now possible using “reversed()” methods. The “reversed” method returns a reverse iterator. Example as follows:

kv_dict = {
     "key_1": "Value 1",
     "key_2": "Value 2",
     "key_3": "Value 3",
     "key_4": "Value 4",
     "key_5": "Value 5"
 }
 rev_kv_dict = reversed(kv_dict)
 for k in rev_kv_dict:
     print(k)   # this will print the keys in reverse order of the initial dictionary

Improved readability on Assignment expressions:

Python 3.8 implemented the walrus operator which will allow assigning value to any variable as a part of another larger expression. The below example will demonstrate how the value of “x ^ 2” has been assigned to variable “n” and used in the “if” conditional statement.

x = 6
if (n := x ^ 2) > 0: 
    print("Final Value: {}".format(n))

New module: metadata

Python “importlib” now have a module called “metadata” which allow to read metadata (e.g. Version) for third-party packages.

f-string: elegant string formatting syntax

This will allow developers to print variable and it’s value inside a string itself. It helps a lot in terms of debugging something on the go. Example as follows:

t_data = 10

print(f’Data: {t_data}’)    # only print value of the variable
print(f’Data: {t_data=}’)   # print both variable & it's value

Vectorcall: Fast calling protocol for CPython

The “vectorcall” protocol is added to the Python/C API as a provisional feature which is aimed to make public from Python 3.9 onwards. It will help formalizing existing optimizations that were already done for various classes. 

There are few other important feature upgrades been made to the version 3.8 which has been listed in the official Python release notes as mentioned below: https://docs.python.org/3/whatsnew/3.8.html