0

Does it allow Python to compare if else condition multiple value at once?

take an example (A, B, C) < (X, Y, Z) ==> A < X, B < Y, C < Z I want to make the following code:

if (195,161,85) < (210, 50, 55):
     print("true")
else:
     print("false")

the output i expect is "false" because 161 > 50 and 85 > 55. Can this be done in python?

Titouan L
  • 1,182
  • 1
  • 8
  • 24
Walrus
  • 1
  • 1
  • If you take a look at that duplicate you'll see that "yes" this compares each element to each corresponding element in your two tuples, but "no" it won't work as expected with numbers as the comparison is lexicographical, not numerical. So `"161">"50"` is `False` – JNevill Mar 07 '22 at 16:00
  • 2
    @Aryo assuming your tuples as t1 and t2: `all(x – mozway Mar 07 '22 at 16:14
  • @mozway thankss a lot, it works – Walrus Mar 07 '22 at 17:36

0 Answers0