ProgrammingEasyTCS NQT · Infosys pattern
What is printed?
What is printed?
d = {"a": 1}
print(d.get("b", 0), "a" in d, 1 in d, d.get("b"))- A. 0 True False None
- B. 0 True True None
- C. None True False 0
- D. 0 True False KeyError
Correct answer: A. 0 True False None
get returns the default (0) for a missing key, or None when no default is given; it never raises KeyError. The in operator on a dict checks KEYS, so "a" in d is True and 1 in d is False even though 1 is a value.
More Python Programming questions
- What is printed? python print(list("ab") + ["c"], tuple([1, 2]) 2)
- What is printed? python d = {"a": 1} try: d["k"] except KeyError as e: print(repr(e), e.args, len(d))
- What is printed? python print([x if x % 2 else -x for x in range(5)], [x for x in range(5) if x % 2 or x == 0])
- What is printed? python print(int(" -0012 "), int("1000"), float("1e3"), int("101", 2), int(-2.9))
- What is printed? python def g(): try: yield 1 yield 2 finally: print("cleanup", end=" ") it = g() print(next(it), end=" ") it.close()…
- What is printed? python data = [4, 7, 1, 9] best = 0 hi = [best := x for x in data if x > best] print(hi, best, "x" in globals())