Language Syntax

Pattern mapping — Python syntax

Match specified keys and corresponding value patterns in an eligible mapping. Extra keys are allowed; an optional double-star capture collects them in a new dictionary. Lookup uses mapping get semantics, so a defaultdict does not create a missing key. Mapping keys in a pattern are literal or dotted value patterns, not arbitrary expressions.

Formal Syntax & Structure

python syntaxpython
case {key_pattern: value_pattern, **rest}: suite

Working Example

Example Snippetpython
match {'kind':'ok','value':7,'extra':9}:    case {'kind':'ok','value':v,**rest}:        result=v,restprint(result)
Python Reference