ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
n = float('nan')
print(n in [n], float('nan') in [n], n == n, [n] == [n])- A. True False False True
- B. False False False True
- C. True True False True
- D. True False True True
Correct answer: A. True False False True
Membership tests in a list check identity before equality, so the same nan object is found. A new nan object is not identical to n and is not equal to it, and n == n is False.
More Python Programming questions
- What is printed? python print(0.1 + 0.2 in [0.3], 0.3 in [0.1 + 0.2], round(0.1 + 0.2, 1) in [0.3])
- What is printed? python print(1 in {1.0: 'a'}, '1' in {1: 'a'}, 1.0 in {True: 1}, {1, True, 1.0})
- What is printed? python d = {} d[1.0] = 'x' d[1] = 'y' print(d, len(d), d[True])
- What is printed? python print(sorted(['b', 'a', 'c'], key=lambda s: -ord(s)))
- What is printed? python print(sorted([0.5, -0.5, 0, True, False], key=abs))
- What is printed? python print(str(2100)[:5], len(str(2100)), str(2100).count('0'))