We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7a104b4 commit 155fc5dCopy full SHA for 155fc5d
python.md
@@ -404,6 +404,22 @@ elif some_var < 10: # This elif clause is optional.
404
else: # This is optional too.
405
print("some_var is indeed 10.")
406
407
+# Match/Case — Introduced in Python 3.10
408
+# It compares a value against multiple patterns and executes the matching case block.
409
+
410
+command = "run"
411
412
+match command:
413
+ case "run":
414
+ print("The robot started to run 🏃♂️")
415
+ case "speak" | "say_hi": # multiple options (OR pattern)
416
+ print("The robot said hi 🗣️")
417
+ case code if command.isdigit(): # conditional
418
+ print(f"The robot execute code: {code}")
419
+ case _: # _ is a wildcard that never fails (like default/else)
420
+ print("Invalid command ❌")
421
422
+# Output: "the robot started to run 🏃♂️"
423
424
"""
425
For loops iterate over lists
0 commit comments