Python 3.10 match multiple arguments

Question:

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?

Asked By: Rodrigo

||

Answers:

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")
Answered By: Barmar

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

Answered By: codester_09
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.