ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(1 if [] == [] is True else 0, [] is [], () is ())
- A. 0 False True
- B. 1 False True
- C. 0 True True
- D. 0 False False
Correct answer: A. 0 False True
[] == [] is True is a chain: the first comparison is True, but [] is True is False, so the condition is False and the result is 0. Two separate empty lists are distinct objects, while empty tuples are a shared singleton.
More Python Programming questions
- What is printed? python print(len(str(float(10300))), str(float(1022))[:4], float(1022) == 1022)
- What is printed? python print(10 // 3, 10 % 3, divmod(10, 3), (10 // 3) 3 + 10 % 3)
- What is printed? python print([1, 2, 3].index(2), 'abc'.index('bc'), (1, 2).index(2), [1, 2, 3].count(4))
- What is printed? python print(float('-0') == 0, str(float('-0')), str(0 -1.0), 0.0 -1)
- What is printed? python print(1 < 2 < 3 < 4 == 4.0, 4 == 4.0 != 5, 1 < 3 > 2 < 2)
- What is printed? python print(oct(0o17 + 0b11), 0x10 | 0o7, 10 + 0x1)