Matching Sequences and Mappings
Destructure lists and dicts.
Patterns That Destructure
The real power of match is destructuring. Sequence and mapping patterns let you check the shape of data and pull values out at the same time.
Matching a Fixed-Length List
A sequence pattern in square brackets matches a list or tuple of that exact length, binding each element to a name.
point = [3, 4]
match point:
case [x, y]:
print('x =', x, 'y =', y)All lessons in this course
- match and case Basics
- Matching Sequences and Mappings
- Class Patterns
- Guards and Wildcards