ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
import sys a = [] b = a c = [a, a] print(sys.getrefcount(a) - sys.getrefcount([]) >= 3, c[0] is c[1], [a] == [b])
- A. True True True
- B. False True True
- C. True False True
- D. True True False
Correct answer: A. True True True
a is referenced by the names a and b and twice from c, so its reference count is at least 3 higher than that of a temporary empty list. Both slots of c hold the same object, and equal contents make the lists equal.
More Python Programming questions
- What is printed? python x = (1, 2, 3) y = x + (4,) z = x 0 print(len(y), z, x.count(2), x.index(3), 3 in x)
- What is printed? python s = "a1b22c333" digits = "".join(ch for ch in s if ch.isdigit()) letters = [ch for ch in s if ch.isalpha()]…
- What is printed? python def f(n, memo={}): if n in memo: return memo[n] r = n if n < 2 else f(n - 1) + f(n - 2) memo[n] = r return r f(10)…
- What is printed? python def f(): x = 1 def g(): return x x = 2 return g def h(): for x in [1, 2]: pass return lambda: x print(f()(), h()())
- What is printed? python class Node: def init(self, v, nxt=None): self.v, self.nxt = v, nxt def iter(self): n = self while n: yield n.v n =…
- What is printed? python import heapq h = [5, 1, 4] heapq.heapify(h) heapq.heappush(h, 0) small = heapq.heappop(h) print(small, h[0]…