ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print(*[f'{i}{ch}' for i, ch in enumerate('ab', 1)])- A. 1a 2b
- B. 0a 1b
- C. 2a 3b
- D. 1a 2b 2
Correct answer: A. 1a 2b
enumerate with start=1 counts from 1 rather than 0. Each pair is joined into a string in the comprehension, and print with * shows each one separated by a space.
More Python Programming questions
- 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))
- What is printed? python print(sorted([3, 1, 2], key=lambda x: -x)[0], sorted('bca', key=lambda c: c > 'a'))