Skip to content

Instantly share code, notes, and snippets.

@tchamberlin
Last active January 26, 2023 18:36
Show Gist options
  • Save tchamberlin/d54b09b2e07de65466d71daf08697def to your computer and use it in GitHub Desktop.
Save tchamberlin/d54b09b2e07de65466d71daf08697def to your computer and use it in GitHub Desktop.
History of major Python features
Version Feature Description
3.4 (2014)
Path Library (pathlib.Path) Representing paths as strings works, but it is much more convenient to represent them as Path objects, which "know" that they are paths! Path objects know if they exist on disk, can be easily concatentated with other paths, are agnostic to the underlying fileystem/OS, etc.
3.5 (2015)
Fast directory scans (os.scandir()) os.walk() is slow; os.scandir() is fast!
Additional Unpacking Generalizations * iterable unpacking operator and ** dictionary unpacking operators now allow unpacking in more positions, an arbitrary number of times, and in additional circumstances
3.6 (2016)
Literal String Formatting (f-strings) Instead of "{}, {}".format(last_name, first_name), you can now do f"{last_name}, {first_name}"
Underscores in Numeric Literals Quick, what's the value of 1000000000? Okay it's 1 Billion, but wouldn't that be easier to understand as 1_000_000_000?
3.7 (2018)
breakpoint() No more import ipdb; ipdb.set_trace()!
Data Classes Mutable named tuples with defaults
3.8 (2019)
Assignment Expressions Allow creation of variables within an expression. Useful within comprehensions, avoiding re-computation of an expression, as well as providing clearer syntax
f-strings support a handy = specifier for debugging Minor enhancement to format strings (from 3.7), but very useful for debugging
3.9 (2020)
Add Union Operators To dict Cleaner alternative to {}.update(**{}):

>>> {"a": "b"} | {"c": "d"}{"a": "b", "c": "d"}
String methods to remove prefixes and suffixes Currently using something like "a123".lstrip("a")? Well, that's a bug. New methods fit this use case (finally)
3.10 (2021)
Structural Pattern Matching Kind of a switch statement, but really not at all. Honestly best via a video
Add Optional Length-Checking To zip (zip strict) Avoid bugs due to mismatched lengths in zip: zip(list_1, list_2, strict=True)
3.11 (2022)
Enhanced error locations in tracebacks (better tracebacks) Much better syntax for locating errors within tracebacks
3.12 (2023*)
Even better error messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment