ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
try:
list(zip([1, 2], [3], strict=True))
except ValueError:
print('length mismatch')
print(list(zip([1, 2], [3])))- A. [(1, 3)] length mismatch
- B. length mismatch [(1, 3), (2, None)]
- C. length mismatch [(1, 3), (2, 3)]
- D. length mismatch [(1, 3)]
Correct answer: D. length mismatch [(1, 3)]
With strict=True, zip raises ValueError when the lengths differ, and the except branch prints the message. The second line uses the default behaviour, which stops at the shorter input.
More Python Programming questions
- What is printed? python print([f'{i}{ch}' for i, ch in enumerate('ab', 1)])
- What is printed? python from itertools import groupby print([(k, len(list(g))) for k, g in groupby('aabbaa')])
- What is printed? python print('a,b'.split(',', -1), 'a,b,c'.split(',', 0), 'a b c'.split(maxsplit=1))
- What is printed? python print(bytes.fromhex('de ad'), (255).tobytes(2), bytes([1, 2]).hex(' '))
- What is printed? python print(round(1.5, 0), round(-2.5), round(2.5, 0) == 2, round(0.5, 0) == 0)
- What is printed? python from math import floor, ceil, trunc print(floor(-0.5), ceil(-0.5), trunc(-0.5), floor(2))