July 6th, 2024

Summary of Major Changes Between Python Versions

The article details Python updates from versions 3.7 to 3.12, highlighting async/await, Walrus operator, Type hints, F-strings, Assignment expressions, Typing enhancements, Structural Pattern Matching, Tomllib, and useful tools.

Read original articleLink Icon
Summary of Major Changes Between Python Versions

The article provides a comprehensive overview of the major changes introduced in various versions of Python, starting from Python 3.7 to Python 3.12. It covers significant updates such as async and await, Walrus operator, Type hints, F-strings, and more in earlier versions. Python 3.8 introduced features like Assignment expressions and Self-documenting f-strings. Python 3.9 brought improvements in Typing with Builtin Generics and Remove Prefix/Suffix functionalities. Python 3.10 introduced Structural Pattern Matching and enhancements in Typing with TypeAlias and TypeGuard. Python 3.11 included updates like Tomllib, Exception Groups, and enriching exceptions with notes. Python 3.12 featured enhancements in Typing with Type Parameter Syntax, F-string changes, and the Buffer protocol. The article also mentions useful tools like Ruff, Pyupgrade, and Black for linting and code formatting. It serves as a valuable resource for developers looking to understand and leverage the new features and improvements in each Python version efficiently.

Related

The Prototype's Language

The Prototype's Language

The evolution of programming languages in payments technology sector is discussed, highlighting the shift from COBOL to Java and now to Python for its speed and adaptability. Language choice impacts developers and work quality.

What's up Python? Django get background tasks, a new REPL, bye bye gunicorn

What's up Python? Django get background tasks, a new REPL, bye bye gunicorn

Several Python updates include Django's background task integration, a new lightweight Python REPL, Uvicorn's multiprocessing support, and PyPI blocking outlook.com emails to combat bot registrations, enhancing Python development and security.

Elixir for Python Developers

Elixir for Python Developers

This comparison delves into Python and Elixir, emphasizing syntax disparities and distinctive traits. Elixir prioritizes immutability and pattern matching, while Python focuses on object-oriented elements. Both share list comprehensions and parallel processing, yet Elixir's functional approach and pattern matching distinguish it. Elixir's Stream module supports lazy operations for big data, contrasting Python's I/O streams. Python developers can benefit from exploring Elixir.

Migrating from Java 8 to Java 17 II: Notable API Changes Since Java 8

Migrating from Java 8 to Java 17 II: Notable API Changes Since Java 8

The article details API changes in Java versions 9 to 17, emphasizing improvements for Java 8 migrations. Changes include null handling, performance enhancements, string improvements, switch expressions, record classes, and utility additions for developer productivity and code readability.

Python Modern Practices

Python Modern Practices

Python development best practices involve using tools like mise or pyenv for multiple versions, latest Python version, pipx for app running. Project tips include src layout, pyproject.toml, virtual environments, Black, flake8, pytest, wheel, type hinting, f-strings, datetime, enum, Named Tuples, data classes, breakpoint(), logging, TOML config for efficiency and maintainability.

Link Icon 11 comments
By @omerhac - 3 months
Wow this is much needed. Thanks! I keep hearing rumors that a no GIL version is coming, I think this is probably the biggest change so far, as it would make the language much more performance oriented. I'm considering a tech stack and thinking about both python and Mojo for ML, not sure that Mojo is stable yet, but the performance differences are HUGE.
By @xcmark - 3 months
Interesting list. I need none of it except the guaranteed dict insertion order!

But of course, I have to learn all of it to understand other people's code. Python's syntax has really gotten worse. The match statement is ugly in comparison to functional languages, I'm not sure about f-strings, the with-statement extension adds new overhead to the reader.

Python is really like C++ now, except 50 times slower (yes, I know about the slow std::unordered_map special case that is due to its rigid specification).

By @bentinata - 3 months
As someone who haven't been using Python extensively since college, and mostly use TypeScript and Kotlin at work (and little bit of Rust for hobby projects), that's a lot of typing features. It feels like for the past few years typing been getting more attention. Good to see.

I used to hate TypeScript (circa 2016) because it kept bugging me with typing errors, and I used to sprinkle "any" to shut it up.

By @hprotagonist - 3 months
https://nedbatchelder.com/text/which-py.html

Ned’s list is what I usually use.

By @ptmcg - 3 months
In this snippet

```python if header.startswith("X-Forwarded-"): section = header.removeprefix("X-Forwarded-") ```

the `startswith()` check is unnecessary. If `header` doesn't start with "X-Forwarded-" then `header.removeprefix("X-Forwarded-")` just returns `header`.

Nice summary doc, with good examples. You can also visit [this site of mine](https://ptmcg.pythonanywhere.com/python_nutshell_app_a_searc...) to search for changes by version (3.7-3.11).

By @m1r3k - 3 months
Nice overview. Are the performance Advantages mentioned?

I didn't know about the pyupgrade tool. Very useful.

By @the__alchemist - 3 months
It was nice to see the "annotations" from 3.7 for helping avoid types with circular imports (for types). I didn't know that!

I'd love to see a step further, and avoid the circular import problem entirely. It's something I fight with everything time I work in Python. I find that I am forced to structure my Python programs in a way specifically designed to avoid this instead of what makes sense for organization. Or I will C+P functions if I feel that tradeoff is not worth it.

By @screye - 3 months
This is great. Python is my main language and I learned a lot.

The piping and typing changes are so useful ! Bookmarked and I'll be coming back to this often.

I also caught the sleep token references. Well done .

By @stenius - 3 months
It's incredible to see how much stuff has been added over the last couple of years.

I've missed a lot of these that I'm going to take advantage of!

By @rubslopes - 3 months
Happy to see that my gripe with f-strings was solved in 3.12. Now you can have quotes inside it!