Python 3.10
Python 3.10 was released in October 2021, will receive bug fixes until May 2023, and will receive security patches until October 2026.
Pattern matching – PEP 634
By far, the most controversial addition to the Python 3.10 pattern matches was bringing match
and case
to the language. This addition consists of three different PEPS: PEP 634, PEP 635, and PEP 636. This new syntax allows you to mirror-switch structures that you might have seen in other languages:
match code:
case 1:
print("Working as expected")
case -1 | -2 | -3:
print("Internal Error")
case _:
print("Unknown code")
Note that to specify one of the multiple values, you need to use the |
operator and not a comma. Using a comma will try to match a list...