ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(sum([[1], [2, 3]], []), sum([[1], [2]], [0]) if False else 'skip')
- A. [1, 2, 3] skip
- B. [1, 2, 3] [0, 1, 2]
- C. 6 skip
- D. Error skip
Correct answer: A. [1, 2, 3] skip
sum with a list start concatenates the lists, giving [1, 2, 3]. The second expression takes the else branch, so it prints 'skip' without calling sum on lists of numbers.
More Python Programming questions
- What is printed? python print(''.join(sorted(set('hello'), key=ord)))
- What is printed? python print(len({0.0, -0.0, 1}), hash(1) == hash(1.0) == hash(True))
- What is printed? python print(1 == 1.0 == True, {1: 'a'}.get(True))
- What is printed? python print([i j for i, j in zip(range(3), range(3, 0, -1))])
- What is printed? python print(''.join(chr(ord('a') + (ord(c) - ord('a') + 3) % 26) for c in 'xyz'))
- What is printed? python import math print(len(str(math.factorial(200))))