in
Size: a a a
in
AG
💭П
RB
💭П
match shape:
case Point(x, y):
...
case Rectangle(x, y, _, _):
...
print(x, y) # This works
💭П
match number:
case 0:
print("Nothing")
case 1:
print("Just one")
case 2:
print("A couple")
case -1:
print("One less than nothing")
case 1-1j:
print("Good luck with that...")
RB
💭П
This is used to match against constants and enum values. Every dotted name in a pattern is looked up using normal Python name resolution rules, and the value is used for comparison by equality with the matching expression (same as for literals). As a special case to avoid ambiguity with name patterns, simple names must be prefixed with a dot to be considered a reference:
💭П
::
и всякими ->
?💭П
case ._: ...
case _.a: ...
RB
::
и всякими ->
?RB
💭П
match input:
case [x, y] if x > MAX_INT and y > MAX_INT:
print("Got a pair of large numbers")
case x if x > MAX_INT:
print("Got a large number")
case [x, y] if x == y:
print("Got equal items")
case _:
print("Not an outstanding input")
💭П
SA
SA
RB
case ._: ...
case _.a: ...
Author:
Brandt Bucher <brandtbucher at gmail.com>
Tobias Kohn <kohnt at tobiaskohn.ch>
Ivan Levkivskyi <levkivskyi at gmail.com>
Guido van Rossum <guido at python.org>
Talin <viridia at gmail.com>