ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
x = [1, 2, 3] print(x * 2, [x] * 2 == [[1, 2, 3], [1, 2, 3]], x + [4] is x, [] == False, not [])
- A. [2, 4, 6] True False False True
- B. [1, 2, 3, 1, 2, 3] True False True True
- C. [1, 2, 3, 1, 2, 3] False False False True
- D. [1, 2, 3, 1, 2, 3] True False False True
Correct answer: D. [1, 2, 3, 1, 2, 3] True False False True
* repeats a list rather than scaling it, and + builds a new list. An empty list is falsy but not EQUAL to False; == compares a list with a bool and returns False.
More Python Programming questions
- What is printed? python t = 1, 2, u = (3) v = () w = (4,) 0 print(type(t).name, len(t), type(u).name, v == w, (1, 2) < (1, 2, -1))
- What is printed? python class Err(Exception): def init(self, code): super().init(f"code {code}") self.code = code try: try: raise Err(7)…
- What is printed? python def check(v): assert v > 0, f"bad {v}" return v try: check(-1) except AssertionError as e: print("AE", e, end=" ")…
- What is printed? python it = iter([1, 2]) try: while True: print(next(it), end=" ") except StopIteration as e: print("stop", e.value…
- What is printed? python def f(): try: return [1] finally: pass def g(): x = [1] try: return x finally: x.append(2) def h(): x = 1 try…
- What is printed? (Output lines are shown separated by " / ".) python class P: def init(self, x): self.x = x def eq(self, o): return self.x…