ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print([10, 20][True], [10, 20][False])
- A. 20 10
- B. 10 20
- C. 20 20
- D. TypeError
Correct answer: A. 20 10
bool is a subclass of int, and True equals 1 when used as an index. So [10, 20][True] reads index 1, which holds 20.
More Python Programming questions
- What is printed? python print(repr('ab' -1), [1] 0, 'a' 3 == 'aaa')
- What is printed? python print(all([]), any([]), all([0, 1]), any([0, '']))
- What is printed? python print([3, 1].sort() or 'x', sorted([3, 1]) == [1, 3])
- What is printed? python try: try: 1 / 0 except ZeroDivisionError: raise ValueError('bad') except ValueError as e…
- What is printed? python print(sorted([(1, 2), (1,), (0, 9, 9)]))
- What is printed? python print('abcabc'.find('c', 3, 5), 'abcabc'.rfind('a', 0, 4))