0

I am a bit confused about how tuples are executed in python especially with conditional statements. Here is the code

one = 1
two = 2
three = 3
four = 4
five = 5
six = 6

if (one, two, three) < (four, one, six):
    print("Bilal rashid 123")
else:
    print("rashid")

I think the overall output should be False but instead it is true. Below is a picture of what statments I think should be true:enter image description here

Can someone please explain how this execution works?

  • You are asking how tuples are *ordered*, i.e how they behave when you use `<` and the like on them. Well, they are ordered lexicographically, like other sequences (str, list) – juanpa.arrivillaga Jan 31 '22 at 23:17
  • that is kinda of confusing because I am not understanding that out of the three statements 2 of them are true and one is false so should that not return False overall? – mirrat rashid Jan 31 '22 at 23:18
  • 2
    It's the same way alphabetical order works (hence the name "lexicographical"). `"apple" < "bag"` because `"a" < "b"`; it doesn't matter that `"p" > "a"` and `"p" > "g"`. – chepner Jan 31 '22 at 23:25
  • @mirratrashid please see the linked duplicate. Also, read about lexicographic ordering (which is sort of a generalization of alphabetical ordering) – juanpa.arrivillaga Feb 01 '22 at 00:16

0 Answers0