ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
a = [3, 1, 2]
b = a.sort() or a
c = sorted(a, reverse=True)
a.reverse()
print(b, c, b is a)
  1. A. [1, 2, 3] [3, 2, 1] True
  2. B. None [3, 2, 1] False
  3. C. [3, 2, 1] [3, 2, 1] True
  4. D. [1, 2, 3] [3, 2, 1] False

Correct answer: C. [3, 2, 1] [3, 2, 1] True

a.sort() returns None, so `None or a` evaluates to a itself (b is a). After a.reverse() the shared list reads [3, 2, 1], which is what b shows too.

More Python Programming questions

Exams that ask this topic