ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(sum([[1], [2, 3]], []))
- A. [1, 2, 3]
- B. [1, 2, 3, 3]
- C. [1, 2]
- D. [[1], [2, 3], 9]
Correct answer: A. [1, 2, 3]
sum with an empty list as the start value concatenates the inner lists, because + on lists joins them.
More Python Programming questions
- What is printed? python x = (1, [2]) x[1].append(3) print(x)
- What is printed? python print(max([1, 5, 3], key=lambda v: -v))
- What is printed? python print(list(map(int, '1 2 3'.split()))[::-1])
- What is printed? python print(f'{7:03d}|{-7:d}|')
- What is printed? python x = 7 print(f'{x=}', f'{x 2 = }', f'{"a"!r:>4}')
- What is printed? python import keyword print(keyword.iskeyword('match'), keyword.issoftkeyword('match'), keyword.iskeyword('None')…