ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print(list(map(len, ['ab', 'c', ''])), list(filter(None, [0, 1, '', 'a'])), any([]), all([]))
- A. [2, 1, 0] [1, 'a'] False True
- B. [2, 1, 0] [1, 'a'] True True
- C. [2, 1] [1, 'a'] False True
- D. [2, 1, 0] [0, 1] False True
Correct answer: A. [2, 1, 0] [1, 'a'] False True
map(len) gives the lengths, and filter(None) drops falsy values such as 0 and the empty string. any of an empty iterable is False, and all of an empty iterable is True.
More Python Programming questions
- What is printed? python print('%d items' % 3, '%s' % 3.0, '%s' % None, '%r' % None)
- What is printed? python print(10 3 == 1000.0, 1e3 == 10 3, type(10 3).name, type(1e3).name)
- What is printed? python print(bin(5), oct(8), hex(16), int('101', 2) + int('7', 8))
- What is printed? python print(sorted(['apple', 'Banana', 'cherry'], key=str.lower), sorted(['apple', 'Banana', 'cherry']))
- What is printed? python print(sum(range(5)) / len(range(5)), sum([1, 2, 3, 4]) // 4, 9 // 2 2 + 9 % 2)
- What is printed? python print(str(3) + str(4) == '34', 3 + 4 == 7, '3' + '4' == 7)