Lists & Tuples · Question 20 · Hard

Tuples of different lengths are compared. What does this print?

print((1, 2, 3) < (1, 3), (2, 1) < (2,))
  1. False False
  2. True True
  3. False True
  4. True False
Answer and explanation

Answer: D. True False

Explanation: Tuples are compared element by element from the left. In the first pair 1 equals 1 and then 2 < 3, so it is True without looking at lengths. In the second pair (2,) is a prefix of (2, 1), and the shorter one is the smaller, so (2, 1) < (2,) is False.

Previous: Two slices with negative values are taken from a list. What does this print?

Practise lists & tuples

Try a fresh set of lists & tuples questions with an explanation after every answer, free and without signing up: Lists & Tuples practice. Or sit a full placement mock test.

More lists & tuples questions

More python practice

Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge