ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
a = [1, 2, 3] b = a[:] print(a == b, a is b, a[:] is a[:], id(a) == id(b), a.copy() == list(a))
- A. True False True False True
- B. True True False True True
- C. True False False False True
- D. True False False True True
Correct answer: C. True False False False True
Each slice creates a new list object (so `is` comparisons are False) with equal contents. Two lists alive at the same time have different ids.
More Python Programming questions
- A service catches errors with except Exception: around its main loop. Which of the following will NOT be caught by that handler?
- For a Python list a with n elements, which operation is O(n) in the worst case (not amortised O(1))?
- How many of these statements about CPython are correct? 1. A tuple is hashable only if all its elements are hashable. 2. x in someset is…
- In CPython, two threads each run a pure-Python CPU-bound loop (no I/O, no C extensions releasing the lock) on a 4-core machine. Compared…
- Which statement about iterables and iterators is correct?
- Assertion (A): After t = (1, 2, [3]), the statement t[2].append(4) succeeds and changes what print(t) shows. Reason (R): A tuple's…