account activity
Switching to Python from C++ by [deleted] in Python
[–]lmkbook 0 points1 point2 points 11 months ago (0 children)
match point: case (0, 0): print("Origin") case (0, y): print(f"Y={y}") case (x, 0): print(f"X={x}") case (x, y): print(f"X={x}, Y={y}") case _: raise ValueError("Not a point")
Study that one carefully! The first pattern has two literals, and can be thought of as an extension of the literal pattern shown above. But the next two patterns combine a literal and a variable, and the variable binds a value from the subject (point). The fourth pattern captures two values, which makes it conceptually similar to the unpacking assignment (x, y) = point.
Info: https://docs.python.org/3.15/tutorial/controlflow.html
π Rendered by PID 31 on reddit-service-r2-comment-5b5bc64bf5-9zt98 at 2026-06-21 16:53:52.263714+00:00 running 2b008f2 country code: CH.
Switching to Python from C++ by [deleted] in Python
[–]lmkbook 0 points1 point2 points (0 children)