Glossary · Phase 7 · Software engineering
Pattern matching
Python's match statement: compare a value against patterns of shape, like a list of two items or a dict with a type key, and pull out its parts.
Try it now
Step through the second call: the three-word case's shape fits but its guard fails, so matching moves on to the general case.
Learn it properly
Pattern matching · match and case: literal, sequence, mapping and class patterns with guards. About 35 minutes.
Never trained an AI?
Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account.