ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print(len([1, 2, 3] * 2), [1, 2] + [3], [0] * 0, [[0] * 2] * 2 == [[0, 0], [0, 0]])
- A. 6 [1, 2] [] True
- B. 6 [1, 2, 3] [] True
- C. 6 [3] [] True
- D. 5 [1, 2, 3] [] True
Correct answer: B. 6 [1, 2, 3] [] True
[1, 2, 3] * 2 repeats the list twice, giving six items. Adding lists concatenates them, and multiplying a list by zero gives an empty list. The nested [[0] * 2] * 2 has two references to the same inner list, which still compares equal.
More Python Programming questions
- What is printed? python print('Hello'.lower() == 'hello', 'Hello'.islower(), 'hello'.isalpha(), 'h3llo'.isalnum())
- What is printed? python print(0.1 + 0.2 > 0.3, round(0.1 + 0.2, 2) == 0.3, 3 0.1 == 0.3, 1 / 3 3 == 1)
- What is printed? python print(max([]) if False else 'none', min([5, 2, 8]), sum([]), sum([[1], [2]], []))
- 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([]))