ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
a = b = []
a.append(1)
c, d = [], []
c.append(1)
x = y = 5
x += 1
print(b, d, y)
  1. A. [] [] 5
  2. B. [1] [1] 6
  3. C. [1] [] 6
  4. D. [1] [] 5

Correct answer: D. [1] [] 5

Chained assignment a = b = [] binds both names to ONE list, so the append is seen through b. c and d are two separate lists. x += 1 rebinds x to a new int; y keeps 5.

More Python Programming questions

Exams that ask this topic