Structural Pattern Matching
match/case (3.10+) matches values by shape — literals, sequences, mappings and class patterns.
Intermediate
match message:
case {"type": "reading", "value": float(v)}:
log(v)
case ["move", x, y]:
move(x, y)
case Point(x=0, y=0):
print("origin")
case _:
print("unknown")
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.