ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
a, b = 1, 2 a, b = b, a + b c = [3, 4] c[0], c[1] = c[1], c[0] m, n = n, m = 7, 8 print(a, b, c, m, n)
- A. 2 3 [4, 3] 8 7
- B. 2 4 [4, 3] 7 8
- C. 2 3 [4, 4] 8 7
- D. 2 3 [4, 3] 7 8
Correct answer: A. 2 3 [4, 3] 8 7
Tuple assignment evaluates the right side first: (a, b) = (2, 1 + 2). The chained assignment assigns the tuple (7, 8) to `m, n` first and then to `n, m`, leaving n = 7 and m = 8.
More Python Programming questions
- What is printed? python b = "Hé".encode("utf-8") print(len("Hé"), len(b), b[1], b.decode("latin-1"))
- What is printed? python b = b"abc" print(b[0], b[:1], list(b"hi"), bytes([65, 66]), b"a" + bytearray(b"b"))
- What is printed? python print(chr(ord("a") + 25), ord("A") - ord("a"), "".join(chr(ord(c) ^ 32) for c in "PyThOn"), str(b"x", "ascii"))
- What is printed? python print(min([], default=0), max([2, 7], default=0), min("b", "a", key=ord), sum([[1], [2]], []))
- What is printed? python for kw in [{}, {"strict": True}]: try: print(list(zip("ab", [1, 2, 3], kw)), end=" ") except ValueError…
- What is printed? python def g(): yield from range(2) yield from "ab" return "done" def h(): r = yield from g() yield r print(list(h())…