Python 3.10 is finally adding some much-needed features
New Python release introduces new feature inspired by C and Java
When you purchase through links on our site, we may earn an affiliate commission.Here’s how it works.
The next stable version of popularopen sourceprogramming language,Python3.10, has been released, bringing with it a host of new syntax and typing features that’ll appeal to long-time developers.
Python 3.10 follows the languages’ 30th anniversary earlier this year in February 2021, and though it doesn’t have a long list of new features, the latest release includes a new type union operator to help developers write cleaner code.
The developers have also polished the interpreter, in the hopes that the changes will make Python code a little easier to debug. For starters, error messages will finally point to where the error actually is, while making sure the error message is informative enough to help the developers take corrective action.
However, the big feature of the release is structural pattern matching, which reportedly grew out of earlier failed attempts to add a switch/case-like syntax to Python.
Structural pattern matching
With structural pattern matching developers can match variables against one of a set of possible values, without relying onif/else/elifblocks for handling expression values anymore. Some developers suggest that the feature can be thought of as being similar to aswitchstatement in C and Java.
Interestingly however, structural pattern matching in Python also enables developers to match against patterns of values.
The feature is implemented via a match statement that “takes an expression and compares its value to successive patterns given as one or more case blocks,” and is designed to equip developers with an easier way to extract information from complex data types.
Are you a pro? Subscribe to our newsletter
Sign up to the TechRadar Pro newsletter to get all the top news, opinion, features and guidance your business needs to succeed!
The Python developers have explained and illustrated the feature in the release notes with relevant examples, and have also provided anin-depth tutorialto help developers get to grips with it.
ViaDevClass
With almost two decades of writing and reporting on Linux, Mayank Sharma would like everyone to think he’sTechRadar Pro’sexpert on the topic. Of course, he’s just as interested in other computing topics, particularly cybersecurity, cloud, containers, and coding.
7 myths about email security everyone should stop believing
Best Usenet client of 2024
NYT Strands today — hints, answers and spangram for Sunday, November 10 (game #252)