ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
a = float('nan')
b = float('nan')
print(a == a, a is a, a == b, [a] == [a], [b] == [a])- A. False False False True False
- B. False True True True True
- C. False True False True False
- D. False True False False False
Correct answer: C. False True False True False
NaN is not equal to anything, including itself, so a == a is False. The identity test a is a is True, and list comparison checks identity before equality, so [a] == [a] is True while [b] == [a] is False.
More Python Programming questions
- What is printed? python print(253 + 1 == 253 + 1.0, 253 + 1 == 253, float(253 + 1) == 253)
- What is printed? python pairs = [(2, 'b'), (1, 'z'), (2, 'a'), (1, 'y')] print(sorted(pairs, key=lambda t: t[0])) print(sorted(pairs…
- What is printed on the second line? python words = ['pear', 'fig', 'apple', 'kiwi', 'date'] print(sorted(words, key=lambda w: (-len(w)…
- What is printed? python print(('ab' 3).count('aba'), 'ababa'.count('aba'), 'aaaa'.count('aa'))
- What is printed on the third line? python print('a,b,,c'.split(',')) print(' a b '.split()) print(' a b '.split(' '))
- What is printed? python print(int('0x1f', 16), int('0x1f', 0), int(' -12 '), int('1000'))