Skip to content
Related Articles
Open in App
Not now

Related Articles

Awesome New Features in Python 3.8

Improve Article
Save Article
  • Last Updated : 29 Oct, 2021
Improve Article
Save Article

Python is a widely-used general-purpose, high-level programming language. It was initially designed by Guido van Rossum in 1991 and developed by Python Software Foundation. It was mainly developed for emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code. Python is a programming language that lets you work quickly and integrate systems more efficiently.
Python 3.8 contains many small improvements over the earlier versions. This article outlines the most significant additions and changes in python 3.8

Positional-only parameters(/)

There is a new function parameter syntax “/” which indicates that some function parameters must be specified positionally and can’t be used as keyword arguments. The addition of “/” improves the language’s consistency and allows a robust API design.


# Arguments before / are considered
# as positional arguments only
def add(x, y, /, z = 0):
    a = x + y + z
# Driver's code
print(add(2, 5))
print(add(2, 5, 7))
print(add(x = 2, y = 5))



Traceback (most recent call last): 
File “”, line 1, in 
TypeError: add() got some positional-only arguments passed as keyword arguments: ‘x, y’ 

The marker “/” means that passing values for x and y can only be done positionally, but not using keyword arguments.

Assignment Expressions(:=)

This operator is used to assign and return a value in the same expression. This removes the need for initializing the variable upfront. The major benefit of this is it saves some lines of code. It is also known as “The Walrus Operator” due to its similarity to the eyes and tusks of a walrus.


a = 20
if (b := a) > 10:
    print(f"The value of b is {b} and is greater than 10.")


The value of b is 20 and is greater than 10.


f-strings now support “=”

This string formatting mechanism is known as Literal String Interpolation or more commonly as F-strings (because of the leading f character preceding the string literal). The idea behind f-strings is to make string interpolation simpler. Python 3.8 allows the use of the above-discussed assignment operator and equal sign (=) inside the f-strings.
For example, say we have two variables “a” and “b”, and we want to print “a + b” along with the result. Here we can use f-strings=.



a = 5
b = 10
# Using = at the end of
# f-strings
print(f'{a + b = }')
# Using assignment operators
# inside f-strings
print(f'{(c := a + b)}')
print("The value of c:", c)


a + b = 15
The value of c: 15

This is very useful during debugging, especially for everyone who uses print() statements for debugging.

reversed() works with a dictionary

Unlike Python 3.7, now in Python 3.8, the built-in method “reversed()” can be used for accessing the elements in the reverse order of insertion.


# Declaring a dictionary
my_dict = dict(x = 1, y = 2, z = 3)
# Prints only keys
# Prints the key-value pair
# as a list of tuples


['z', 'y', 'x']
[('z', 3), ('y', 2), ('x', 1)]

No parentheses for return and yield statements

‘yield’ and ‘return’ statements do not require parentheses to return multiple values.

For example:


def parse(family):
  lastname, *members = family.split()
  return lastname.upper(), *members
print(parse('Charles David John Sam'))


('CHARLES', 'David', 'John', 'Sam')

pow() function

In the three-argument form of pow(), when the exponent is -1, it calculates the modular multiplicative inverse of the given value.

For example, to compute the modular multiplicative inverse of 38 modulo 137:


print(pow(38, -1, 137))



Syntax Warning

If you miss a comma in your code such as a = [(1, 2) (3, 4)], instead of throwing TypeError, it displays an informative Syntax warning like this:

SyntaxWarning: 'tuple' object is not callable; perhaps you missed a comma?

Dictionary comprehension

Dict comprehensions have been modified so that the key is computed first and the value second:

>>> data = {input('Name: '), input('Age: ')}
Name: Charles
Age: 40

‘csv’ module

The ‘csv.DictReader’ now returns instances of dictionary instead of a ‘collections.OrderedDict’.


importlib_metadata is a new library added in the Python’s standard utility modules, that provides an API for accessing an installed package’s metadata, such as its entry points or its top-level name.
Example: The version of pip can be checked using this module. 


from importlib import metadata
# pip version
data = metadata.metadata('pip')


Metadata-Version: 2.1 
Name: pip 
Version: 9.0.1 
Summary: The PyPA recommended tool for installing Python packages. 
Author: The pip developers 
License: MIT 
Description: pip 
The `PyPA recommended 
tool for installing Python packages. 
* `Installation `_ 
* `Documentation `_ 
* `Changelog `_ 
* `Github Page `_ 
* `Issue Tracking `_ 
* `User mailing list `_ 
* `Dev mailing list `_ 
* User IRC: #pypa on Freenode. 
* Dev IRC: #pypa-dev on Freenode. 
.. image:: 
.. image:: 
.. image:: 
.. image:: 
Code of Conduct 
Everyone interacting in the pip project’s codebases, issue trackers, chat 
rooms, and mailing lists is expected to follow the `PyPA Code of Conduct`_. 
.. _PyPA Code of Conduct: 
Keywords: easy_install distutils setuptools egg virtualenv 
Platform: UNKNOWN 
Classifier: Development Status :: 5 – Production/Stable 
Classifier: Intended Audience :: Developers 
Classifier: License :: OSI Approved :: MIT License 
Classifier: Topic :: Software Development :: Build Tools 
Classifier: Programming Language :: Python :: 2 
Classifier: Programming Language :: Python :: 2.6 
Classifier: Programming Language :: Python :: 2.7 
Classifier: Programming Language :: Python :: 3 
Classifier: Programming Language :: Python :: 3.3 
Classifier: Programming Language :: Python :: 3.4 
Classifier: Programming Language :: Python :: 3.5 
Classifier: Programming Language :: Python :: Implementation :: PyPy 
Requires-Python: >=2.6,!=3.0.*,!=3.1.*,!=3.2.* 
Provides-Extra: testing 



  • In Python 3.8, the multiprocessing module offers a SharedMemory class that allows regions of memory to be created and shared between different Python processes. Shared memory provides a much faster path for passing data between process, which eventually allows Python to use multiple processors and multiple cores more efficiently.
  • Many built-in methods and functions have been speed up by 20% to 50%.
  • Newly created lists are now on average 12% smaller than before
  • Writes to class variables are much faster in Python 3.8.


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!