ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print([i for i in range(10) if i % 3 == 0][::-1], [i * i for i in range(5)][-2:], len([]) == 0)
- A. [0, 3, 6, 9] [9, 16] True
- B. [9, 6, 3, 0] [9, 16] True
- C. [9, 6, 3, 0] [4, 9] True
- D. [9, 6, 3, 0] [9, 16] False
Correct answer: B. [9, 6, 3, 0] [9, 16] True
The filter keeps 0, 3, 6 and 9, and reversing puts 9 first. The last two squares are 9 and 16, and an empty list has length zero.
More Python Programming questions
- What is printed? python print('%.2f' % 1.255, '%.2f' % 1.245, '%.1f' % 0.05, '%.1f' % 0.15)
- What is printed? python print(str(1e-4), str(1e-5), str(123456789.0), str(1234567890123456789.0))
- What is printed? python print(18 // 4 if False else 'na', 'na' 2 + 'ba')
- What is printed? python print(all(c.islower() for c in 'abc'), any(c.isdigit() for c in 'abc'), 'abc'.isascii() and 'é'.isascii())
- What is printed? python from collections import deque d = deque('abc') d.rotate(1) d.appendleft('z') print(''.join(d), d.pop())
- What is printed? python print(len(bin(255)), bin(255).count('0'), bin(-255).count('1'))