ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(any(x > 2 for x in [1, 2, 3]), next(x for x in [1, 2, 3] if x > 1))
- A. True 3
- B. True 2
- C. False 2
- D. True 1
Correct answer: B. True 2
any stops at the first item greater than 2, which is 3, so the result is True. next returns the first item greater than 1, which is 2.
More Python Programming questions
- What is printed? python print(list(range(5, 0, -2)), list(range(0)), range(3)[1:])
- What is printed? python print('x'.join('abc'), 'abc'.join('x'))
- What is printed? python print(True + True, 3 True, 'ab' True)
- What is printed? python print('%.3e' % 12345.678)
- What is printed? python print(sorted([3, 1, 2], reverse=True) == [3, 2, 1], [3, 1, 2][::-1])
- What is printed? python print([0] 3 == [0, 0, 0], [[]] 2 == [[], []])