ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
nan = float("nan")
L = [nan]
print(nan == nan, nan in L, L == [nan], [float("nan")] == [float("nan")])- A. False True True False
- B. False False False False
- C. False True False False
- D. True True True True
Correct answer: A. False True True False
Container membership and equality first check identity (x is y) before ==. The same nan object is found in L and makes L == [nan] true, but two separately created nans are different objects that compare unequal.
More Python Programming questions
- What is printed? python from collections import OrderedDict a = {"x": 1, "y": 2} b = {"y": 2, "x": 1} c = OrderedDict(a) e =…
- What is printed? python from collections import defaultdict d = defaultdict(list) d["a"].append(1) = d["b"] print("c" in d, d.get("c")…
- What is printed? python from collections import Counter a = Counter("aabbbc") b = Counter("abccd") print(sorted((a - b).items())…
- What is printed? python a = {"x": 1, "y": 2} b = {"y": 3, "z": 4} c = a | b a |= {"w": 0} print(c, b | a)
- What is printed? python d = {i: i i for i in range(4)} try: for k in d: if k == 1: del d[k] except RuntimeError: print("RE", end=" ") for…
- What is printed? python d = {"a": 1} v = d.values() k = d.keys() d["b"] = 2 print(list(v), k - {"a"}, "b" in k)