ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
a = [1, 2, 3] b = a a += a c = [1, 2] c.append(c) print(b, len(c), c[2][2][0], c)
- A. [1, 2, 3] 3 1 [1, 2, [...]]
- B. [1, 2, 3, 1, 2, 3] 3 1 RecursionError
- C. [1, 2, 3, 1, 2, 3] 3 1 [1, 2, [...]]
- D. [1, 2, 3, 1, 2, 3] 4 1 [1, 2, [1, 2]]
Correct answer: C. [1, 2, 3, 1, 2, 3] 3 1 [1, 2, [...]]
a += a extends the shared object with a copy of its own items. A list containing itself is legal; indexing c[2] returns c again, and repr shows the cycle as [...].
More Python Programming questions
- What is printed? python s = "The quick brown fox" w = s.split() print(" ".join(w[::-1]), " ".join(x[::-1] for x in w)[:9], max(w, key=len))
- What is printed? python d = {} for w in "to be or not to be".split(): d[w] = d.get(w, 0) + 1 best = max(d, key=d.get) print(best…
- What is printed? python class Stack(list): def push(self, v): self.append(v) return self s = Stack() s.push(1).push(2) t = s + [3]…
- What is printed? (Output lines are shown separated by " / ".) python def f(, a, b=2): return a - b def g(a, b=2, /): return a - b…
- What is printed? python def outer(fn): def w(a, k): return fn(a, k) 2 return w class C: @outer def val(self, x): return x + 1 @property…
- What is printed? python def log(prefix): def deco(fn): def w(a): return prefix + str(fn(a)) return w return deco @log("A:") @log("B:") def…