ProgrammingVery hardHCL · Tech Mahindra · Python placement

What does the following Python 3 code print? print(id([1, 2]) == id([1, 2]))

  1. A. Error
  2. B. True
  3. C. False
  4. D. None

Correct answer: B. True

In CPython, the first temporary list is garbage-collected (refcount drops to 0) before the second is created, so the allocator can reuse the same memory address and id.

More Python Programming questions

Exams that ask this topic