Welcome to Python 3.8

Srijan Sahay
Nov 1, 2019 · 4 min read

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

Image for post
Image for post
Python 3.8

Some of the new features of Python 3.8 are:

1. The walrus operator

Image for post
Image for post

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:

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}’)
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.

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.

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.
Image for post
Image for post

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.

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.

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


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.

The Startup

Medium's largest active publication, followed by +755K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store