ProgrammingEasyTCS NQT · Infosys pattern
What is printed?
What is printed?
print(list("ab") + ["c"], tuple([1, 2]) * 2)- A. ['ab', 'c'] (1, 2, 1, 2)
- B. ['a', 'b', 'c'] (2, 4)
- C. ['a', 'b', 'c'] (1, 2, 1, 2)
- D. ['ab', 'c'] ((1, 2), (1, 2))
Correct answer: C. ['a', 'b', 'c'] (1, 2, 1, 2)
list("ab") iterates the string, giving ['a', 'b']; + joins two lists. Multiplying a sequence by an integer repeats it, so (1, 2) * 2 is (1, 2, 1, 2), not element-wise doubling.
More Python Programming questions
- What is printed? python d = {"a": 1} try: d["k"] except KeyError as e: print(repr(e), e.args, len(d))
- What is printed? python print([x if x % 2 else -x for x in range(5)], [x for x in range(5) if x % 2 or x == 0])
- What is printed? python print(int(" -0012 "), int("1000"), float("1e3"), int("101", 2), int(-2.9))
- What is printed? python def g(): try: yield 1 yield 2 finally: print("cleanup", end=" ") it = g() print(next(it), end=" ") it.close()…
- What is printed? python data = [4, 7, 1, 9] best = 0 hi = [best := x for x in data if x > best] print(hi, best, "x" in globals())
- What is printed? python class M: def init(self, v): self.v = v def add(self, o): return M(self.v + (o.v if isinstance(o, M) else o)) ms =…