I have 3 conditions, each one in a variable (a, b, and c)
I want to match the order and their values on a match
statement
def main():
a = "ABC"
b = 2
c = 3
match a, b, c:
case "ABC" | 2 | 3:
print("match all")
if __name__ == "__main__":
main()
Is this possible? If yes, how?
CodePudding user response:
The case
pattern should be structured just like the value you're matching, so it should be a tuple.
match (a, b, c):
case ("ABC", 2, 3):
print("match all")
CodePudding user response:
match a, b, c:
case "ABC" | 2 | 3:
print("match all")
Actually, Your code check if (a,b,c)
equals to a
or equals to b
or equals to c
. That is always False
That's why you get nothing(None
) in the output