You can even use them to finally destructure objects and dicts, although it's a little hacky:
d = {'a': 1, 'b': 2, 'c': 3}
match d:
case { 'a': 1, 'b': b, **rest }:
pass
print(b, rest) # prints 2, {"c": 3}
from dataclasses import dataclass
@dataclass
class Point:
x: int
y: int
z: int
p = Point(4, 5, 6)
match p:
case Point(4, y, z):
pass
print(y, z) # prints 5, 6
33
u/Gravbar Feb 02 '24
TIL py finally added switch statements