ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print(max([]) if False else 'none', min([5, 2, 8]), sum([]), sum([[1], [2]], []))
- A. none 5 0 [1, 2]
- B. none 2 0 [1, 2]
- C. none 2 None [1, 2]
- D. none 2 1 [1, 2]
Correct answer: B. none 2 0 [1, 2]
The conditional picks 'none' because the test is False. min is 2, sum of an empty list is 0, and summing a list of lists with an empty list start concatenates them into [1, 2].
More Python Programming questions
- What is printed? python print(float('3.0') == 3, int(float('3.9')), round(3.5) + round(4.5), 3 == 3.0 == 3)
- What is printed? python s = 'abc' 2 print(s.count('a'), s.index('c'), s[2::3], len(s.split('b')))
- What is printed? python print(list(map(len, ['ab', 'c', ''])), list(filter(None, [0, 1, '', 'a'])), any([]), all([]))
- 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))