+ 3
Control Flow
What does match case do in Python?
7 odpowiedzi
+ 8
it known as switch statements, it work like if/else.
+ 6
Alhaaz ,
your comment that python `match ... case` can not handle float values is *not* correct.
it requires python 3.10 +, (the current version of sololearn is 3.9.18)
https://sololearn.com/compiler-playground/c3TAJXE2T92P/?ref=app
+ 4
When you have to compare something several times, you can write a bunch of IF statements. Match Case is a simple way to do that. You can always do this with IF statements. But it's a little easier to read like this.
Look at this function:
def http_error(status):
match status:
case 400:
return "Bad request"
case 404:
return "Not found"
case 418:
return "I'm a teapot"
+ 3
Okay 👍👍. Thank you 🙏🙏🙏🙏 for the feedback.
+ 2
Thank you 🙏🙏🙏🙏🙏
+ 2
yes, Sololearn's Python version is not updated yet, so you cannot use it here... you get a syntax error instead.
+ 2
It helps to align the code on it