ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
a = [1, 2, 3, 4]
b = a
a = a.extend([5]) or a
print(a is b, b[-1], [].extend([1]))
  1. A. False 5 None
  2. B. True 5 None
  3. C. True 4 None
  4. D. True 5 [1]

Correct answer: B. True 5 None

extend mutates in place and returns None, so `None or a` evaluates to a itself, the same object as b. extend on a temporary list also returns None.

More Python Programming questions

Exams that ask this topic