ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
x = [0, 1] i = 0 x[i], i = 5, 1 j = 1 j, x[j] = 0, 7 print(x, i, j)
- A. [5, 7] 1 0
- B. [7, 1] 1 0
- C. [5, 1] 1 0
- D. [7, 7] 1 0
Correct answer: B. [7, 1] 1 0
Targets are assigned left to right after the whole right side is evaluated. First x[0] = 5 (i is still 0), then i = 1. Next j = 0 happens before x[j], so x[0] = 7 overwrites the 5.
More Python Programming questions
- What is printed? python 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)
- 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…