Track 12 · Lesson 9 of 12
Enums and structural pattern matching
Replace magic strings with enum members, and take data apart by shape with match: class patterns, mapping patterns, guards and the capture-pattern trap.
You will be able to
- Define enumerations with enum.Enum and auto() and use their name and value
- Convert outside data to enum members and reject unknown values
- Match objects with class patterns and dicts with mapping patterns, including guards
- Avoid the capture-pattern trap by matching dotted names such as Status.PAID
Included with a Formula Quest membership
It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.
View Formula Quest memberships
Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.