ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
nan = float("nan")
print(max(nan, 1), max(1, nan), min(nan, 1), nan in {nan})- A. nan nan nan False
- B. 1 1 1 True
- C. nan 1 nan True
- D. nan 1 1 False
Correct answer: C. nan 1 nan True
max/min keep the first item and replace it only when a later item compares greater (or smaller); every comparison with NaN is False, so the result depends on argument order. Set membership checks identity first, so the same nan object is found.
More Python Programming questions
- What is printed? python print(max([1, 2], [1, 2, 0]), min("Z", "a", ""), sorted([True, 0, -1, 0.5]), max(3, 3.0), max(3.0, 3))
- What is printed? python print(bin(-5), (-5).bitlength(), ~5, -5 >> 1, -5 & 0b111, 5 ^ -1)
- What is printed? python print("10" + "5", int("10") + 5, "10" 2, str(10) 2 == "1010", "5" < "10")
- What is printed? python a = "hello" try: a[0] = "j" except TypeError: a = "j" + a[1:] b = a.replace("l", "X", 1) print(a, b…
- What is printed? python print(1000 == 1000, 0.1 + 0.7, 7 / 2 == 7 // 2 + 0.5, 2 0.5 2, (-8) (1 / 3) == -2)
- What is printed? python s = "racecar" print(s.index("c"), s.rindex("c"), s.find("c", 3), s[::-1] is s, s.count("a", 2))