Python 3.8 : Are the New Features Really Worth It?
Python 3.8.0 (beta 3) was released on the 29th of July, 2019. While some Python Developers agree that there are significant changes in Python 3.8, there are others who feel that the changes make no impact for a developer, especially for one in the field of Data Science.
So, what’s to be expected for a Python programmer who is yet to try out the new version? According to the Python website, here are some of the new features that we will be seeing –
1. Positional Only Parameter:
Consider a simple addition Function,
def sum(a, b, c=None):
x=a+b
if c != None:
x=x+c
return x
This function will give us the value of x, based on the values of a, b, and c, specified by us. By default, c will have no value. However, if we do give it a value, it will be added to the final sum. The result would look something like this,
Case 1:
Input -> sum(1,2,3)
Output -> 6
We can also get the answer in this way,
Case 2:
Input -> sum(b=3, a=2)
Output -> 5
Thus, we find that we can enter the values based on the position (Case 1) or on the keyword (Case 2).
In Python 3.8, something called the Positional Only Parameter has been introduced, which enables us to specify whether the values of a function are to be entered based only on position, or also on keyword. This parameter is the ‘/’. So, with this Parameter, the function would look something like this,
def sum(a, b, c=None, /):
x=a+b
if c != None:
x=x+c
return x
Thus, we can enter the values as we did in Case 1 to get an answer, while if we entered the values as we did in Case 2, we would receive an error message.
2. Assignment Expressions:
The ‘:=’ operator, also known as the ‘Walrus Operator’, allows us to assign a value to a variable as a part of an Expression, without initially assigning any value to that variable.
Consider the example,
if (a:=2) is not None:
print(a)
This ‘:=‘ operator will assign the value ‘2’ to the previously undefined variable ‘a’, and then print its value.
3. Pickle Protocol 5 with Out of Band Data:
First, let us understand what ‘Pickling’ is in Python. Pickling is used to serialise or deserialise a Python object structure. So, we can convert Python objects (like lists, dictionaries, etc.) into streams of characters.
Second, let us understand what ‘out of band’ data is. This is the type of data that is transferred through a stream, and which is independent from the main ‘in–band’ stream of data.
Thus, there is a new Pickle version, Protocol 5, for handling this type of ‘out of band’ data.
The full article by Nikita Silaparasetty can be read on the 'AI For Women' blog, at:
http://aiforwomen.org/python-3-8-how-significant-are-the-new-features/
As a Python Developer, what do you think about these changes? Do you think they are beneficial, or, as some have said, are they insignificant?
Good one Nikita!
Absolutely amazing