Language Syntax

Pattern or — Python syntax

Try alternatives left to right and stop at the first successful pattern. Alternatives must bind the same set of names; only the final alternative may be irrefutable. This vertical bar is pattern syntax, not a bitwise expression.

Formal Syntax & Structure

python syntaxpython
case pattern1 | pattern2: suite

Parameters & Attributes

NameTypeDescription
pattern1patternFirst alternative.
pattern2patternNext alternative with identical binding set.

Working Example

Example Snippetpython
match ('right',7):    case ('left',n) | ('right',n):        result=nprint(result)
Python Reference