The NEW Match-Case Statement in Python 3.10

Python 3.10 is beginning to fill out with plenty of fascinating new features. One of those, in particular, caught my attention - structural pattern matching - or as most of us will know it, switch/case statements.

Switch-statements have been absen…


This content originally appeared on DEV Community and was authored by James Briggs

Python 3.10 is beginning to fill out with plenty of fascinating new features. One of those, in particular, caught my attention - structural pattern matching - or as most of us will know it, switch/case statements.

Switch-statements have been absent from Python despite being a common feature of most languages.

Back in 2006, PEP 3103 was raised, recommending the implementation of a switch-case statement. However, after a poll at PyCon 2007 received no support for the feature, the Python devs dropped it.

Fast-forward to 2020, and Guido van Rossum, the creator of Python, committed the first documentation showing the new switch-statements, which have been named Structural Pattern Matching, as found in PEP 634.

Python switch-statements are not just switch-statements, they are much more powerful thanks to their structural pattern matching capabilities.

Let's take a look at how this new logic works.


This content originally appeared on DEV Community and was authored by James Briggs


Print Share Comment Cite Upload Translate Updates
APA

James Briggs | Sciencx (2021-04-20T15:10:07+00:00) The NEW Match-Case Statement in Python 3.10. Retrieved from https://www.scien.cx/2021/04/20/the-new-match-case-statement-in-python-3-10/

MLA
" » The NEW Match-Case Statement in Python 3.10." James Briggs | Sciencx - Tuesday April 20, 2021, https://www.scien.cx/2021/04/20/the-new-match-case-statement-in-python-3-10/
HARVARD
James Briggs | Sciencx Tuesday April 20, 2021 » The NEW Match-Case Statement in Python 3.10., viewed ,<https://www.scien.cx/2021/04/20/the-new-match-case-statement-in-python-3-10/>
VANCOUVER
James Briggs | Sciencx - » The NEW Match-Case Statement in Python 3.10. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/20/the-new-match-case-statement-in-python-3-10/
CHICAGO
" » The NEW Match-Case Statement in Python 3.10." James Briggs | Sciencx - Accessed . https://www.scien.cx/2021/04/20/the-new-match-case-statement-in-python-3-10/
IEEE
" » The NEW Match-Case Statement in Python 3.10." James Briggs | Sciencx [Online]. Available: https://www.scien.cx/2021/04/20/the-new-match-case-statement-in-python-3-10/. [Accessed: ]
rf:citation
» The NEW Match-Case Statement in Python 3.10 | James Briggs | Sciencx | https://www.scien.cx/2021/04/20/the-new-match-case-statement-in-python-3-10/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.