ProgrammingHardCapgemini · Infosys pattern
What is printed?
What is printed?
print(all([1, 2, 3]), all([1, 0, 3]), any([0, 0, 0]), any([0, 1, 0]))
- A. True True False True
- B. True False False True
- C. True False True True
- D. False False False True
Correct answer: B. True False False True
all() is True only if every element is truthy: [1,2,3] all truthy (True); [1,0,3] has a 0 (False). any() is True if at least one is truthy: [0,0,0] all falsy (False); [0,1,0] has a 1 (True).
More Python Programming questions
- What is printed? python x = None print(x or "default") y = 0 print(y or "default") z = "" print(z or "fallback")
- What is printed? python def gen(): try: x = yield 1 except GeneratorExit: print("closing") raise g = gen() next(g) g.close()
- What is printed? python a = 5 def outer(): x = 10 def inner(): nonlocal x x += a return x return inner() print(outer())
- What is printed? python class Temperature: def init(self, celsius=0): self.celsius = celsius @property def fahrenheit(self): return…
- What is printed? python def f(a, b, , c=10, kwargs): return a + b + c + sum(kwargs.values()) print(f(1, 2, d=3, e=4)) print(f(1, 2, c=100))
- What is printed? python class Animal: sound = "..." def makesound(self): return f"{type(self).name} says {self.sound}" class Dog(Animal)…