educative.io

How is this giving true. I am confused here

d1 = [1,2,3,4]

d2 = [5,6,7,8]

print(d2>d1)

Output: True

because 5>1, it will always compare the first element.

Hey Mohammad_Alim!

It is because the list is compared in order. It starts from the first item of each list.

  • If both items are unequal, as 1 and 5 are unequal in the example, the comparison result is returned.
  • If both items are equal, the items at the next index of each list are compared.

Thank you for asking the question. We hope Educative has inspired you to further your learning.