How to compare multiple variables to the same value?

You want to test a condition for all the variables:

if all(x >= 2 for x in (A, B, C, D)):
    print(A, B, C, D)

This should be helpful if you’re testing a long list of variables with the same condition.


If you needed to check:

if A, B, C, or D >= 2:

Then you want to test a condition for any of the variables:

if any(x >= 2 for x in (A, B, C, D)):
    print(A, B, C, D)

Leave a Comment