Language Syntax

Pattern sequence — Python syntax

Match eligible sequence subjects by length and item patterns. A starred capture collects remaining items in a list. Strings, bytes and bytearray are excluded even though they support sequence operations. Arbitrary iterators are not automatically matched as sequences. There may be at most one starred subpattern.

Formal Syntax & Structure

python syntaxpython
case [first, *rest]: suite

Working Example

Example Snippetpython
def split(v):    match v:        case [first,*rest]:            return first,rest        case _:            return Noneprint((split((1,2,3)),split('abc')))
Python Reference