ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = [1, 2] x += x x *= 2 print(x)
- A. [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
- B. [1, 2, 1, 2, 1, 2, 1, 2]
- C. [1, 2, 1, 2]
- D. [1, 2, 1, 2, 1, 2]
Correct answer: B. [1, 2, 1, 2, 1, 2, 1, 2]
x += x extends the list with its own items, giving four items. x *= 2 doubles that to eight.
More Python Programming questions
- What is printed? python d = dict(zip('abc', range(3))) print(d.popitem(), d)
- What is printed? python t = (3, 1, 2) print(sorted(t) == list(t), tuple(sorted(t)), t)
- What is printed? python print(max('apple', 'banana', key=len), max([], default=None))
- What is printed? python print([y for x in [1, 2, 3] if (y := x + 1) % 2 == 0])
- What is printed? python print(all(i < j for i, j in zip([1, 2, 3], [2, 3, 3])))
- What is printed? python print(b'abc'[0], b'abc'[0:1], len('é'.encode()))