ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
q = [1, 2, 3] stack = [1, 2, 3] print(q.pop(0), stack.pop(), q, stack, q + stack)
- A. 3 3 [1, 2] [1, 2] [1, 2, 1, 2]
- B. 1 3 [2, 3] [1, 2] [2, 3, 1, 2]
- C. 1 3 [1, 2, 3] [1, 2, 3] [1, 2, 3, 1, 2, 3]
- D. 1 1 [2, 3] [2, 3] [2, 3, 2, 3]
Correct answer: B. 1 3 [2, 3] [1, 2] [2, 3, 1, 2]
pop(0) removes from the front (queue behaviour, O(n) for lists) and pop() from the end (stack behaviour). The arguments are evaluated left to right before printing.
More Python Programming questions
- What is printed? python s = "2024-01-15" y, m, d = map(int, s.split("-")) print(y + m + d, f"{d:02d}/{m:02d}/{y}", s[5:7] == "01")
- What is printed? python scores = [("a", 50), ("b", 80), ("c", 65)] passed = [n for n, s in scores if s >= 60] top = max(scores, key=lambda…
- What is printed? python x = 7 kind = "even" if x % 2 == 0 else "odd" sign = "pos" if x > 0 else "zero" if x == 0 else "neg" print(kind…
- What is printed? python count = 0 for i in range(1, 4): for j in range(i): if (i + j) % 2: continue count += 1 print(count, i, j)
- What is printed? python a = [4, 2, 7] b = a b.sort() c = sorted(a, reverse=True) print(a, c, a is b, c is a)
- What is printed? python s = "banana" print(s.replace("a", "o", 2), s.upper().count("A"), s[::2], s.startswith(("x", "ba")))