ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
print({x % 3: x for x in range(7)})- A. {0: 0, 1: 1, 2: 2}
- B. {0: 3, 1: 4, 2: 5}
- C. {0: 6, 1: 4, 2: 5}
- D. {0: 0, 1: 4, 2: 5, 3: 6}
Correct answer: C. {0: 6, 1: 4, 2: 5}
Keys repeat (x % 3 takes only the values 0, 1, 2), and each later x overwrites the earlier value for that key. The last x for key 0 is 6, for key 1 it is 4, and for key 2 it is 5. Insertion order follows the first time each key appeared.
More Python Programming questions
- What is printed? python print([(i, j) for i in range(3) for j in range(i)])
- What is printed? python def g(): x = yield 1 yield x 2 it = g() print(next(it), it.send(5))
- What is printed? python calls = 0 def f(n): global calls calls += 1 return 1 if n <= 1 else f(n - 1) + f(n - 2) print(f(5), calls)
- What is printed? python import copy a = [[1, 2], [3]] b = copy.copy(a) c = copy.deepcopy(a) a[0].append(9) a.append([4]) print(len(b)…
- What is printed? python x = [1] 3 for i in range(3): x[i] = x[i - 1] + i print(x)
- What is printed? python x = "g" def outer(): x = "o" def inner(): global x x = "i" inner() return x print(outer(), x)