This is a somewhat elegant solution that works if you are running the code in a function:
def foo(x):
c = 1
match x:
case "Hello,":
a()
case "World!":
b()
case "foobar":
c()
case _:
print("Something didn't happen :(")
c = 0
if c == 1:
print("Something happened")
This method makes use of the builtin _
case to run code when NONE of the previous cases are met, and sets the variable once.
If you are running this at the end of the function, you can return
and skip the need for the variable:
...
case _:
print("Something didn't happen :(")
return
print("Something happened")