What's new in Python 3.8?


Do you know that the newer version of python has been released recently? Before the release of the latest version, Python 3.7 was ruling on the hearts of programmers. Now, Python 3.8 will catch their attention. It is loaded with new features that older versions of Python lack. Some modules have been improved too. The latest version was launched officially on October 14th, 2019. Let’s see what features have been added in the newer version.

What's new in Python 3.8?

New features in Python 3.8

  1. Assignment Expression
  2. Meet “the walrus operator” that is used for assigning values to variables. The values are assigned as a part of larger expression. It will save your time in writing code. The syntax of walrus operator is :=

    >>> while (line := file.readline()) != "end": >>> print(world)
    >>>if (n := len(a)) > 10: >>> print(f"List is too long ({n} elements, expected <= 10)")

    In both the example, you can clearly understand the working of the walrus operator. In the second example, len() is avoided twice with the help of assignment expression. It is called a walrus operator because of its similar look to the eyes of and tusks of a walrus. Programmers are advised to use walrus operators in a limited manner to clean cases. This will decrease complexity and improve readability.

  3. Positional Only Parameter
  4. In Python 3.8, you can use slash ‘/’ at the end of the parameter argument when you are defining a function. This syntax is especially for defining functions and keeping the arguments positional. When a parameter is marked positional only, it provides an advantage. In the future, the parameter name can be changed without letting the client’s code break. For example,

    >>>def pow(x, y, z=None, /): >>> r = x**y >>> if z is not None: >>> r %= z >>> return r
  5. Parallel filesystem
  6. A new setting has been introduced known as PYTHONPYCACHEPREFIX. It helps in configuring implicit bytecode cache for using a parallel filesystem tree separately instead of __pycache__ subdirectory in every source directory.

  7. importlib.metadata
  8. A new module has been added called importlib.metadata. It helps in reading metadata from the third party packages. An example of the use of this module is given below.

    >>>from importlib.metadata import version, requires, files >>> version('requests') '2.22.0' >>> list(requires('requests')) ['chardet (<3.1.0,>=3.0.2)'] >>> list(files('requests'))[:5] [PackagePath('requests-2.22.0.dist-info/INSTALLER'), PackagePath('requests-2.22.0.dist-info/LICENSE'), PackagePath('requests-2.22.0.dist-info/METADATA'), PackagePath('requests-2.22.0.dist-info/RECORD'), PackagePath('requests-2.22.0.dist-info/WHEEL')]
  9. F-String Debug Support
  10. It makes easy to print text, computed values or values in an expression by providing a preformat. See in the example below how it works.

    >>>x = 1 >>>print(f'{x+4}')

    The above program will 5 give as output. However, you can add = after f string that will print the text included with it.

    >>>x = 1 >>>print(f'{x+4=}')

    After compiling, it will provide the output as x+4=5.

  11. Multiprocessing Shared Memory
  12. In Python 3.8, you will be offered with multiprocessing.sharedmemory module. It provides a class named SharedMemory that means “System V style” shared memory blocks. It makes it convenient to pass data between multicores or symmetric processors.

  13. Pickel Protocol
  14. Pickle module uses binary protocols to serialize and de-serialize a Python object structure. It records the serialized objects in such a way that the later references won’t be serialized again.

    More details about these features are available in the Python 3.8 documentation. Go through it to understand and know more about some cool new Python 3.8 features.



Best Search Engine:

Sponsored Deals ends in

Thinking of Buying Products Online??

Use Below Search to get Best Discounts Online

Interesting Technical Quizzes:

Online Browser Games:

Search Tags