ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
t = (3, 1, 2)
print(sorted(t) == list(t), tuple(sorted(t)), t)
  1. A. True (1, 2, 3) (3, 1, 2)
  2. B. False [1, 2, 3] (2, 3, 1)
  3. C. False (1, 2, 3) (1, 2, 3)
  4. D. False (1, 2, 3) (3, 1, 2)

Correct answer: D. False (1, 2, 3) (3, 1, 2)

sorted returns a list, and [1, 2, 3] is not equal to [3, 1, 2]. The tuple itself is unchanged by sorted.

More Python Programming questions

Exams that ask this topic