ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
x = (1, 2, 3) y = x + (4,) z = x * 0 print(len(y), z, x.count(2), x.index(3), 3 in x)
- A. 4 (0,) 1 2 True
- B. 4 () 1 3 True
- C. 4 () 2 2 True
- D. 4 () 1 2 True
Correct answer: D. 4 () 1 2 True
Tuple concatenation needs another tuple, (4,). Repeating zero times gives the empty tuple. count and index work like the list versions; 3 sits at index 2.
More Python Programming questions
- 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]…
- What is printed? python from collections import deque d = deque([1, 2, 3], maxlen=3) d.append(4) d.appendleft(0) d.rotate(1)…