ProgrammingModerateCapgemini · Python
What is printed?
What is printed?
print(all([]), any([]), all([0]), any([[]]), any([[0]]))
- A. True False False True True
- B. False False False False True
- C. True False True False True
- D. True False False False True
Correct answer: D. True False False False True
all([]) is True, any([]) is False; all([0]) fails on 0; [] is falsy, but [0] is a non-empty list and so truthy.
More Python Programming questions
- What is printed? python w = ['pear', 'fig', 'apple', 'kiwi', 'date'] print(sorted(w, key=len), sorted(w, key=len, reverse=True))
- What is printed? python print(7 // 2, -7 // 2, 7 % -3, divmod(-7, 2), 2 -1)
- What is printed? python print({x % 3 for x in range(10)}, {x: x x for x in range(3)})
- What is printed? python def f(): try: return 'a' finally: print('f', end=' ') print(f())
- What is printed? python def g(): x = yield 1 print('got', x) y = yield x 2 print('got', y) it = g() print(next(it)) print(it.send(5)) try…
- What is printed? python def mk(): n = 0 def inc(): nonlocal n n += 1 return n return inc a, b = mk(), mk() print(a(), a(), b(), a())