match
Wähle einen Zweig anhand eines Werts. case _ ist der Standard und muss zuletzt kommen.
Syntax
match command:case "N":...case _:...
- case "N" | "S": teilt einen Rumpf. Anführungszeichen sind für Text Pflicht.
Beispiel
cmd = "SCAN"
match cmd:
case "N" | "S":
print("move")
case "SCAN":
print("look")
case _:
print("wait")Ausgabe:
look
Häufige Fehler
- case _ trifft auf alles zu, deshalb muss es zuletzt stehen. "n" und "N" sind verschiedene Werte.