ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
n = float('nan')
print(n in [n], [n] == [n], n == n, n is n)- A. True True False True
- B. False True False True
- C. True False False True
- D. True True False False
Correct answer: A. True True False True
Containers compare elements by identity before equality, so n in [n] and [n] == [n] are True even though nan != nan. The direct comparison n == n is False, and n is n is True.
More Python Programming questions
- What is printed? python print(sum([0.1, 0.2, 0.3]) == 0.6, 0.1 + 0.2 + 0.3 == 0.6, 0.3 + 0.2 + 0.1 == 0.6)
- What is printed? python print(7.5 // 2, 7.5 % 2, -7.5 // 2, divmod(7.5, -2))
- What is printed? python print(max([('x', 5), ('y', 5)], key=lambda t: t[1]), min([('x', 5), ('y', 5)], key=lambda t: t[1]))
- What is printed? python print(sorted([1.0, True, 1, 0.5, False]))
- What is printed? python try: print(int('10')) except ValueError: print('bad')
- What is printed? python print(float('1e400'), -float('1e400'), float('1e308') 10)