(docs.python.org) 8. Compound statements — Python 3.13.5 documentation
ROAM_REFS: https://docs.python.org/3/reference/compound_stmts.html
- 8. Compound statements
Compound statements contain (groups of) other statements; they affect or control the execution of those other statements in some way. In general, compound statements span multiple lines, although in simple incarnations a whole compound statement may be contained in one line.
(docs.python.org) 8.6: The match
statement
ROAM_REFS: https://docs.python.org/3/reference/compound_stmts.html#match
** 8.6. The
matchstatementAdded in version 3.10.
The match statement is used for pattern matching. Syntax:
match_stmt ::= 'match' subject_expr ":" NEWLINE INDENT case_block+ DEDENT
subject_expr ::= star_named_expression "," star_named_expressions?
| named_expression
case_block ::= 'case' patterns [guard] ":" block
Note
This section uses single quotes to denote soft keywords.
Pattern matching takes a pattern as input (following
case) and a subject value (followingmatch). The pattern (which may contain subpatterns) is matched against the subject value. The outcomes are:
- A match success or failure (also termed a pattern success or failure).
- Possible binding of matched values to a name. The prerequisites for this are further discussed below.
The
matchandcasekeywords are soft keywords.See also