A new version of Python was released on October 5, 2020. This technical article will go over some of the highlights of what is new in Python 3.9 that are interesting if you are an Engineer, Scientist or Quant using Python. For all details of what changed, see the Python 3.9 Release Notes.
Before diving into Python 3.9, it is interesting to see the release history of Python and how often it has changed.
Python Version | Release Date | Days |
3.9.0 | 5 October 2020 | 356 |
3.8.0 | 14 October 2019 | 474 |
3.7.0 | 27 June 2018 | 551 |
3.6.0 | 23 December 2016 | 467 |
3.5.0 | 13 September 2015 | 546 |
3.4.0 | 16 March 2014 | 533 |
3.3.0 | 29 September 2012 | 587 |
3.2.0 | 20 February 2011 | 603 |
3.1.0 | 27 June 2009 | 206 |
3.0.0 | 3 December 2008 |
It can be overwhelming to keep up to date with every aspect of what changed between Python 3.8 and Python 3.9. This is VersionBay’s list of main changes that is worthwhile knowing if you are passionate about Python.
- New Features:
- union operator for
dict
- union operator for
- New Module
- zoneinfo – now has support for IANA time zone database to the standard library
- Module Improvements:
- ipaddress – supports scope_id
New union operator
There is a new union operator in Python for dict
. It was introduced as not many people knew about the alternative and now this common task is much more readable. Here is an example:
# Add Union Operator in Python 3.9 d1 = {"Name": "dict", "Python": 3.9} d2 = {"Name": "dict", "Operator":"|"} # in python 3.9 d3 = d1 | d2 print(d3) # before python 3.9 d4 = {**d1, **d2} print(d4)
For more information please see: PEP 584.
zoneinfo
In Python 3.9 there is a new module which is particularly useful: zoneinfo
. Anyone who has used Python and works with dates on a regular basis at a certain moment will stumble across that it is important to know timezones. It is great to see Python now supports IANA time zone database. Here is a small example of how to use it:
from zoneinfo import ZoneInfo from datetime import datetime, timedelta # Daylight saving time dt = datetime(2020, 10, 31, 12, tzinfo=ZoneInfo("America/Los_Angeles")) print(dt) # expected result: 2020-10-31 12:00:00-07:00 dt.tzname() # PDT # Standard time dt += timedelta(days=7) print(dt) # expected result: 2020-11-07 12:00:00-08:00 print(dt.tzname()) # PDT
Please note for the code above to work you will need to install:
pip install tzdata
For more information please see: PEP 615.
ipaddress
In Python 3.9 the ipaddress module got updated and improved by supporting the scope_id. This is not a huge improvement but it made it to our top list as in general the better support for ipaddress the more useful python is. The scope_id is defined as by RFC 4007, this property identifies the particular zone of the address’s scope that the address belongs to, as a string. One can define an ipaddress like this:
<address>%<zone_id>
This article explains the beauty of this. That being said, at the highest level it is becoming more common to use the zone_id or scope_id and seeing core support from Python put a smile on our face.
For more information please see: RFC 4291
If you found this article interesting and would like to learn more about Python Contact Us.