Index Ai Academy
Glossary · Phase 7 · Software engineering

Pattern matching

Also written: match statement

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.

Create a free account See what's in the lesson

Never trained an AI?

Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account.

Teach it to write