Data Structures & AlgorithmsModerateTCS NQT Digital · Python semantics
Problem: What does the following print?
Problem: What does the following print?
print(bool([]), bool([0]), bool(0.0), bool('False'))What is printed?- A. False True True True
- B. False False False True
- C. False True False True
- D. True True False True
Correct answer: C. False True False True
Only empty containers and zero-valued numbers are falsy. The list [0] and the non-empty string 'False' are truthy.
More Coding Interview Problems questions
- Problem: What does the following print? python a = (1,) print(a 3, len(a 0)) What is printed?
- Problem: What does the following print? python print(list('abc')[::-1] == ['c', 'b', 'a'], 'abc'.index('c')) What is printed?
- Problem: What does the following print? python x = 5 x <<= 2 x |= 1 print(x) What is printed?
- Problem: What does the following print? python print(any([]), all([])) What is printed?
- Problem: What does the following print? python print(10 20 // 10 18) What is printed?
- Problem: What does the following print? python print(float('inf') > 10 100, -0.0 == 0.0) What is printed?