3 ms·
Python 3.10 match statements are faster than if-statements
- conaclos 5y agoI like the combination between dataclasses and structural pattern matching: @dataclass class Point: x: int y: int def where_is(point): match point: case Point(x=0, y=0): print("Origin") case Point(x=0, y=y): print(f"Y={y}") case Point(x=x, y=0): print(f"X={x}") case Point(): print("Somewhere else") case _: print("Not a point")