ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
print(0 or [] or "x", 1 and 0 and 5, None or 0)
- A. x 5 None
- B. True False False
- C. [] 0 None
- D. x 0 0
Correct answer: D. x 0 0
or returns the first truthy operand, or the last one if none is truthy. and returns the first falsy operand, or the last one. So 0 or [] or "x" gives "x", 1 and 0 and 5 stops at 0, and None or 0 gives 0 (the last operand).
More Python Programming questions
- What is printed? python x = [1, 2] g = (n 10 for n in x) x.append(3) x = [7] print(list(g))
- What is printed? python class Bag: items = [] def add(self, v): self.items.append(v) a, b = Bag(), Bag() a.add(1); b.add(2) print(a.items…
- What is printed? python class A: def who(self): return "A" class B(A): def who(self): return "B" + super().who() class C(A): def…
- What is printed? python try: try: raise ValueError except TypeError: print("T", end=" ") finally: print("F1", end=" ") except ValueError…
- What is printed? python x = 10 def f(a=x): return a x = 20 print(f())
- What is printed? python print(sum(range(1, 10, 2)), list(range(5))[-1:-4:-1])