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.
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 :=
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.
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,
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.
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.
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.
The above program will 5 give as output. However, you can add = after f string that will print the text included with it.
After compiling, it will provide the output as x+4=5.
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.
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.