Important new features in Python 3.8

The recent Python 3.8 release introduced many interesting new features, optimizations and tweaks. As new Python versions are published, developers must stay up to date with language changes. In this article, we will try to present the most exciting changes.

Assignment operator

The assignment operator lets you create value assignments within larger logic expressions.

Example

>>> if ( value := 1 + 1 ) > 1: # 2 > 1
  print(value)
2
>>>

In this example, we assign 1+1 to a variable (value) and check if it is greater than 1. It is important to note that you can also use an assignment operator inside list comprehension.

New f-strings specifier

Python 3.8 introduces a new ‘=’ specifier available to use inside f-string expressions. The specifier will automatically get the object name with the object value paired.

Example

>>> object='example_value'
>>> f'{object}'
'example_value'
>>> f'object={object}'
'object=example_value'
>>> f'{object=}'
"object='example_value'"
>>> f'{object=!s}'
'object=example_value'
>>>

This new feature will certainly be helpful in testing and logging. As you can see in the example, it is also possible to use this conversion flag with the new specifier.

New importlib.metadata module

New importlib.metadata module can help you read metadata, such as the version number for packages installed with tools like pip. Let’s check the installed version of Django and its requirements.

Example

>>> from importlib import metadata
>>> metadata.version('django')
'3.0'
>>>
>>> metadata.requires('django')
['pytz', 'sqlparse (>=0.2.2)', 'asgiref (~=3.2)', "argon2-cffi (>=16.1.0) ; extra == 'argon2'", "bcrypt ; extra == 'bcrypt'"]
>>>

Removed features in Python 3.8

- The macpath module
- isAlive() method of threading.Thread
- platform.popen() method

Deprecated features in Python 3.8

- getchildren() and getiterator() methods of ElementTree
- lgettext(), ldgettext(), lngettext() and ldngettext() of gettext module



To sum up, if your career path includes Python development, it is worth keeping up to date with python releases systematically. Check out our blog for more news.

Stay connected

Don't miss out on gaining more insights – opt-in to our monthly newsletter, and stay ahead in the ever-evolving world of music technology!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

By submitting this form, you confirm that you have read and agree to the Terms & Conditions.

Table of Contents

Need help?

No matter if you are just getting started or have an advanced concept - reach out to us and let's discuss.

Maciej Dulski

Maciej Dulski
Senior Business Consultant

In need of software development?

At Brave we specialise in Web Software Development. We wiil help you to get your project done.

CONTACT

LET’S TALK

FILL IN THE FORM BELOW, OR REACH OUT TO US DIRECTLY — OFFICE@BRAVELAB.IO

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.