File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -404,6 +404,22 @@ elif some_var < 10: # This elif clause is optional.
404404else : # This is optional too.
405405 print (" some_var is indeed 10." )
406406
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 🏃♂️"
407423
408424"""
409425For loops iterate over lists
You can’t perform that action at this time.
0 commit comments