+ 1

Control Flow

What does match case do in Python?

26th Nov 2024, 11:38 AM
Byrone Songa
Byrone Songa - avatar
3 odpowiedzi
+ 6
it known as switch statements, it work like if/else but cannot handle floating values.
26th Nov 2024, 1:11 PM
Alhaaz
Alhaaz - avatar
+ 3
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"
26th Nov 2024, 1:28 PM
Jerry Hobby
Jerry Hobby - avatar
+ 2
Thank you 🙏🙏🙏🙏🙏
26th Nov 2024, 1:30 PM
Byrone Songa
Byrone Songa - avatar