ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
a, *b, c = range(6) x, y = y, x = 1, 2 print(a, b, c, x, y)
- A. 0 [1, 2, 3, 4] 5 2 1
- B. 0 [1, 2, 3, 4] 5 1 2
- C. 0 (1, 2, 3, 4) 5 2 1
- D. 0 [1, 2, 3, 4, 5] 5 2 1
Correct answer: A. 0 [1, 2, 3, 4] 5 2 1
Starred unpacking collects the middle values into a LIST, not a tuple. In a chained assignment the right-hand value (1, 2) is assigned to each target from left to right: first x, y = 1, 2, then y, x = 1, 2, which overwrites them to y = 1, x = 2. It is not a swap.
More Python Programming questions
- What is printed? python words = ["banana", "Apple", "cherry", "apple"] print(sorted(words), sorted(words, key=str.lower)[:2], max(words…
- What is printed? python i = 10 squares = [i i for i in range(3)] for j in range(3): pass print(i, squares, j)
- What is printed? python s = " Hello, World " print(s.strip().lower().split(","), s.count("l"), s.find("z"), "-".join("abc"))
- What is printed? python def f(args, kw): return len(args), sorted(kw) print(f(1, 2, [3, 4], a=5, {"b": 6}))
- What is printed? python class A: count = 0 def init(self): A.count += 1 self.count = 10 a = A(); b = A() b.count += 5 print(A.count…
- What is printed? python it = iter([1, 2, 3, 4, 5]) pairs = list(zip(it, it)) print(pairs, list(it))