4 ms·
Differences from C's switch: 1. No fallthrough-by-default. 2. Checked for exhaustiveness. This is different from "insisting on a default clause", because if y
by kibwen 10y ago
Differences from C's switch:
1. No fallthrough-by-default.
2. Checked for exhaustiveness. This is different from "insisting on a default clause", because if you see a match with no default clause, then you know that the compiler is verifying that every possible case is being handled.
3. The cases of the match can be arbitrary patterns, not just integers. This allows you to perform very natural and powerful conditional control flow, especially when using tagged unions.
4. Can return a value.
Finally, remember the context of this post: Python doesn't have a C-style switch statement at all. :P