ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(sorted([True, 0, 2, False]))
- A. [False, 0, True, 2]
- B. [0, False, True, 2]
- C. [True, 0, False, 2]
- D. [0, False, 2, True]
Correct answer: B. [0, False, True, 2]
sorted is stable, and 0 equals False, so the 0 that appears earlier in the input comes first. True equals 1 and comes before 2.
More Python Programming questions
- What is printed? python print(7 // 2 2, 7 / 2 2, 2 3 2)
- What is printed? python print([1, 2] < [1, 3], [1, 2] < [1], 'b' > 'abc')
- What is printed? python print(isinstance([], list) and isinstance((), tuple), type([]) == list)
- What is printed? python print(''.join(sorted('hello', key=lambda c: c in 'aeiou')))
- What is printed? python print(len({(1, 2): 'a', (2, 1): 'b', (1, 2): 'c'}))
- What is printed? python x = 5 def f(): return x x = 6 print(f(), (lambda: x)())