ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(sum([True, True, False]), sum([1.5, True]), True * 3 + 0.5, sum([1, 2], 10))
- A. 2 2.5 3.5 13
- B. 3 2.5 3.5 13
- C. 2 2.5 3.5 12
- D. 2 2.5 3.0 13
Correct answer: A. 2 2.5 3.5 13
bool is a subclass of int, so True counts as 1 in sum and arithmetic. The start value 10 is added to 1 + 2, giving 13.
More Python Programming questions
- What is printed? python print(all([]), any([]), all([0, 1]), any([0.0, '']), all(x > 0 for x in [1, -1]))
- What is printed? python print(list(zip('ab', [1, 2, 3])), dict(zip('ab', [1, 2, 3])))
- What is printed? python print(sorted([('b', 1), ('a', 2), ('a', 1)])[1:], sorted({3: 'c', 1: 'a'}.items()))
- What is printed? python print(sorted({'b': 1, 'a': 2}), sorted({'b': 1, 'a': 2}.values(), reverse=True))
- What is printed? python print(len({x % 3 for x in range(10)}), sorted({x x % 5 for x in range(5)}))
- What is printed? python print(list(range(-5, 5, 4)), list(range(5, -5, -4)), range(-1, -4, -1)[0])