ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(0 or [] or 'x', 2 and 0 and 5, None or 0)
- A. x 0 None
- B. False 0 0
- C. x 0 0
- D. x 5 0
Correct answer: C. x 0 0
or returns its first truthy operand and and returns its first falsy operand, so the values themselves are printed. None or 0 returns 0.
More Python Programming questions
- What is printed? python d = {} d.setdefault('k', []).append(1) d.setdefault('k', []).append(2) print(d, d.setdefault('j', 9), 'j' in d)
- What is printed? python w = ['pear', 'fig', 'apple', 'kiwi', 'date'] print(sorted(w, key=lambda s: (len(s), s)), sorted(w, key=len…
- What is printed? python print(bool(0.0), bool(' '), bool(None is None), bool(float('nan')))
- What is printed? python def findmin(a): lo, hi = 0, len(a) - 1 while lo < hi: mid = (lo + hi) // 2 if a[mid] > a[hi]: lo = mid + 1 else…
- What is printed? python g = {'a': [3, 1], 'b': [2]} for v in g.values(): v.sort() print(g, sorted(g.items(), key=lambda kv: len(kv[1])…
- What is printed? python ops = {} for name in ['add', 'mul']: ops[name] = lambda x, y, n=name: x + y if n == 'add' else x y…