Design a site like this with WordPress.com
Get started

Welcome to Python 3.8

Python 3.8

Python 3.8 is the latest major release of the Python programming language, and it contains many new features and optimizations.

Some of the new features of Python 3.8 are:

1. The walrus operator

We have a new kind of assignment operator in this new version called Walrus operator (:=). This operator has the advantage of setting and returning a variable in one line. For example:

Code:
sample_data = [
{“id”: 1, “name”: “Srijan”},
{“id”: 2, “name”: “Abhishek”},
{“id”: 3, “name”: “Dilip”},
{“id”: 4, “name”: “Vishal”},
{“id”: 4, “name”: None},
]
print(“With Python 3.8 Walrus Operator:”)
for entry in sample_data:
    if name := entry.get(“name”):
        print(f’Found name = {name}’)
print(“Without Walrus operator:”)
for entry in sample_data:
    name = entry.get(“name”)
    if name:
        print(f’Found name = {name}’)Output:
With Python 3.8 Walrus Operator:
Found name = “Srijan”
Found name = “Abhishek”
Found name = “Dilip”
Found name = “Vishal”
Without Walrus operator:
Found name = “Srijan”
Found name = “Abhishek”
Found name = “Dilip”
Found name = “Vishal”

2. Positional-only arguments

A special marker ‘/’ can now be used when defining a method’s arguments to specify that the function only accepts positional arguments on the left of the marker. The ‘/’ marker here means that passing values for x, y and z can only be done positional, and not using keyword arguments.
Code:

def func1(x,y,z=None,/):
    r = x + y
    if z is not None:
        r -= z
        return r
print(func1(2, 5)) #7
print(func1(2, 5, 3)) #4
print(func1(x=2, y=10)) #TypeError
print(func1(2, 10, z=3)) #TypeError

3. f-string also support ‘=’

Now you can use ‘=’ operator within f-string to get and print value.
This mean that now we can perform our arithmetic operations within f-string.

a=5
b=6
print(f'sum={a+b}') #11

4. New syntax warning

Python have introduced new warning messages for missing comma along with the error messages in this new version. The interpreter will throw this helpful warning message which will help user to quickly find their error.

list1=[[0,1] [2,3]] #this will give a SyntaxWarning of missing comma along with the TypeError.
Syntax Warning

5. Reversible dictionary

reversed() now works with dictionary. Python has started preserving the order of key inserted in dictionary from 3.7 but now in 3.8 you can also reverse it.

dict1={'a':5,'b':6}
print(dict1)    #{'a': 5, 'b': 6}
print(list(reversed(dict1)))    ['b', 'a']

6. Multiprocessing shared memory

Using multiprocessing, the data can be shared and accessed globally across all the instances of Python. This will speed up saving, storing, accessing, and transferring data with much ease.

7. New protocol for creating pickle files

Pickle in Python is primarily used in serializing and de-serializing data, and code that can be used somewhere else also. In this new version, Python will be using Protocol 4 by default and you can also use Protocol 5 with it. This will result APIs to take full advantage, hence improving the performance.
For people working in field of data science, this is an exciting news as this will work well with Django and Flask even in the servers with low or limited space.

8. Improved CPython

Python has also said that they have improved Python’s C engine. This will make optimizations easy in Python. People from data science field had encountered many instance where the Python or Jupyter environment crashed because of huge amount of data. With improvement in its CPython module, user can expect better result in processing and querying data.

9. Performance improvement

This release have added number of performance that speeds-up the interpreter. Some of them are:

  • operator.itemgetter() is now 33% faster.
  • Field lookups in collections.namedtuple() are now more than two times faster.
  • list constructor now create list of 12% smaller on average.
  • uuid.UUID now uses slots to reduce it’s memory footprint.
  • Invocation of some simple built-ins and methods are now 20–50% faster.

and many more…
To know more, check https://www.python.org/downloads/release/python-380/


Summary

The upcoming release of Python adds some great new features to the language and significantly improves the performance with fundamental speed-up fixes. Let us welcome Python 3.8 and make the best use of it.

Advertisement

Published by Ahmed's

Hello, I’m Ahmed, Crew trainer for Zohr gas field. I am a software engineer, consultant, and Adobe, Autodesk, Microsoft instructor/tutor. Currently living in Dumyat al Jadidah, Damietta, Egypt. My interests range from education to technology. I am also interested in entrepreneurship, programming, and cooking. I'm a member of the Scientific Research Center at the US Embassy.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: