ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
first, *mid, last = "abcde" (a, b), *rest = [(1, 2), 3, 4] *init, = range(3) print(mid, last, a + b, rest, init)
- A. bcd e 3 (3, 4) (0, 1, 2)
- B. ['b', 'c', 'd'] e 3 [3, 4] SyntaxError
- C. ['b', 'c', 'd'] e (1, 2) [3, 4] range(0, 3)
- D. ['b', 'c', 'd'] e 3 [3, 4] [0, 1, 2]
Correct answer: D. ['b', 'c', 'd'] e 3 [3, 4] [0, 1, 2]
A starred target in assignment always collects into a list, even from a string or range. Nested targets unpack (1, 2) into a and b.
More Python Programming questions
- What is printed? python def f(a, b, args, c=0, kw): return a, b, args, c, kw print(f(1, [2, 3, 4], c=5, d=6))
- What is printed? python def f(): for i in range(3): try: return i finally: if i == 0: continue print(f())
- What is printed? python def f(): try: raise KeyError("k") finally: return "swallowed" try: print(f(), end=" ") except KeyError…
- What is printed? python try: try: 1 / 0 except ZeroDivisionError: raise ValueError("v") except ValueError as e…
- What is printed? python try: try: {}["x"] except KeyError as k: raise RuntimeError("r") from None except RuntimeError as e…
- What is printed? python out = [] for x in [1, 0, "a"]: try: r = 10 / x except (ZeroDivisionError, TypeError) as e…