Check if multiple variables have the same value

To check if they are all the same (either 1 or 2):

sameness = (x == y == z)

The parentheses are optional, but I find it improves readability


How about this?

x == y == z == 1

If you have an arbitrary sequence, use the all() function with a generator expression:

values = [x, y, z]  # can contain any number of values
if all(v == 1 for v in values):

otherwise, just use == on all three variables:

if x == y == z == 1:

If you only needed to know if they are all the same value (regardless of what value that is), use:

if all(v == values[0] for v in values):

or

if x == y == z: