Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Cool New Features in Python 3.9 (Summary)

The release of a new Python version is a big milestone for the community. You may not be able to start using the cool new features immediately, but in a few years Python 3.9 will be as widespread as Python 3.6 is today.

In this course, you’ve seen new features like:

  • The zoneinfo module for dealing with time zones
  • Union operators that can update dictionaries
  • More expressive decorator syntax
  • Annotations that can be used for other things besides type hints

Sample Code (.zip)

11.0 KB

Course Slides (.pdf)

526.8 KB

00:00 In the previous lesson, I discussed the pros and cons of upgrading quickly. In this lesson, I’ll give you a quick summary of the course. The first topic was the ZoneInfo class of the new zoneinfo library.

00:13 This provides access to the time zone database on your computer and means you’ll no longer need to use a third-party library or implement your own subclass of timezone.utc.

00:24 After that, I covered the new pipe and pipe equals operators for merging and updating dictionaries. Then I showed you the new decorator syntax that is far more flexible, allowing you to use general, callable expressions as your decorators.

00:39 The Annotated class in the typing library gives you the ability to add meta information to your type hints. Under the covers, one of the bigger changes in Python 3.9 is the change from an LL(1) to a PEG parser. This likely won’t impact you immediately, but allows the developers of Python to support syntax in the future that was very difficult before.

01:02 The str (string) library has two new functions, .removesuffix() and .removeprefix(), for removing the front and back part of a string. It’s now easier to use generics with type hints, as you no longer have to have special classes like capital-L List in the typing process. You can just use the built-in list type.

01:22 graphlib is a new addition to Python 3.9 that does topological graph sorting. I flashed back to grade school and showed you math.gcd() and the new math.lcm() methods.

01:34 And finally, I took you on a bit of a journey with the new HTTP status codes, including 418 I'm a teapot.

01:44 For all the gory details about Python 3.9 and what’s new, this is the main doc you should take a look at.

01:52 Thank you for your attention! I hope you’ve enjoyed the course.

Avatar image for patientwriter

patientwriter on Oct. 15, 2020

Thumbs up!

Avatar image for brunosilvaferreira

brunosilvaferreira on Nov. 28, 2020

Nice work, Prefix and Suffix are my favorites, thank you very much!

Avatar image for rmaschion

rmaschion on Nov. 28, 2020

Very nice! I couldn’t find the demo/c2_dict.py…

Avatar image for Christopher Trudeau

Christopher Trudeau RP Team on Nov. 28, 2020

Hi rmaschion,

Those demo files are internal ones I use to create the presentation. If you’re looking for the sample code on dictionaries, take a look at the “mergedict.repl” file in the Sample Code, available in the “Supporting Materials” drop down on any page in the course. …ct

Become a Member to join the conversation.