Switch-Case Statements Are Coming to Python
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.
What we have here is much more than a simple switch-case statement, however (hence match-case), as we will see soon.
python
example:
http_code = "418"
match http_code:
case "200":
print("OK")
do_something_good()
case "404":
print("Not Found")
do_something_bad()
case "418":
print("I'm a teapot")
make_coffee()
case _:
print("Code not found")
there was a lot of alternative for switch case till now but at last switch case is getting added in python 3.10.![]
Leave Switch-Case Statements Are Coming to Python to:
Read more #tech posts
Best Posts From Spartex
We have not curated any of spartex's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Spartex
- breaking news !!! Over 53 crore Facebook users data leaked from facebook phone numbers, FB IDs, locations, birth dates and more
- Cheak out my noice cash profile for more content
- deleted post
- Every star waits for darkness to shine.....
- PayPal Launches Cryptocurrency Checkout Service in US
- Global Chip Shortage Affects Production of Microwaves, Refrigerators, Other Home Appliances
- Switch-Case Statements Are Coming to Python
- Facebook, Google Plan New Undersea Cables to Connect Singapore, Indonesia, and North America
- First Post