If you want to learn more about the `match` statement":
I have a great article explaining when the `match` statement ISN'T the right tool for the job: π mathspp.com/blog/pydonts/sβ¦
That's it for now!
Do you want to level up your Python π game?
Want to get awesome Python π knowledge and content daily?
Then follow @mathsppblog because that is exactly what I do here on Twitter.
Also, if you found value in this thread, show your love π and retweet it π
Here's a TL;DR
1. `match` declares what object we are looking at; 2. `case` defines the cases we want to handle; 3. `|` separates multiple options; 4. use `if`s after `case`s to refine conditions; 5. use `_` to match any object at all (kind of like an `else`);
6. object destructuring works on custom classes; 7. object destructuring gives access to objects' attributes; 8. __match_args__ allows to remove boilerplate from `case`s; 9. object destructuring on built-ins works like basic type validation; 10. sub-patterns can be named;
11. use `*` with iters to match arbitrary sections; 12. `case` with dict don't check full structure; 13. `case` with dict can check just key or key/value pairs. 14. use `**` to match arbitrary portion of dict; and 15. use `**` with `if` to enforce specific dict structure.
Bye π
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh