ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(next(iter([]), 'none'), next(iter([7])))
- A. nothing 7
- B. none 7
- C. none None
- D. StopIteration 7
Correct answer: B. none 7
next accepts a default that is returned when the iterator is exhausted, so no exception is raised for the empty list. The second call returns the only item, 7.
More Python Programming questions
- What is printed? python x = 3.14159 print(f'{x:.2f}|{42:>5}|{0.5:%}')
- What is printed? python print(0.1 + 0.2 + 0.3 == 0.6, 0.6 == 0.3 2, 0.3 2 == 0.6)
- What is printed? python print(sorted([10, 2, 33], key=str), sorted(['10', '2', '33'], key=int))
- What is printed? python print('%.2f' % 0.125, '%.2f' % 0.375, '%.1f' % 0.05, '%.0f' % 1.5)
- What is printed? python print(-17 % -5, 17 % -5, -17 % 5, -(17 % 5))
- What is printed? python a = 'ab' b = a 3 print(b.count('ab'), b.count('aba'), len(b.split('b')))