ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(float(' 1_0.5 '), float('infinity'), float('-nan') != float('-nan'), float('1_0'))- A. 10.5 inf False 10.0
- B. 105.0 inf True 10.0
- C. 10.5 inf True 10.0
- D. 10.5 nan True 10.0
Correct answer: C. 10.5 inf True 10.0
float() strips surrounding whitespace, accepts underscores between digits, and recognises 'infinity'. NaN never equals anything, so comparing it with itself gives True for !=.
More Python Programming questions
- What is printed? python print(len(bytes(3)), bytes([65, 66]) == b'AB', bytearray(b'ab') == b'ab', type(b'a'[0]).name)
- What is printed? python s = 'abc' t = s s += 'd' print(s, t, s is t)
- What is printed? python a = [1, 2] b = a 2 b[0] = 9 c = a + a c[2] = 7 print(a, b, c)
- What is printed on the first line? python grid = [[0] 2] 2 grid[0][0] = 1 print(grid) g2 = [[0] 2 for in range(2)] g2[0][0] = 1 print(g2)
- What is printed? python t = (1, [2]) t[1].append(3) print(t, len(t)) try: t[0] = 5 except TypeError as e: print(type(e).name)
- What is printed? python print(bin(0b1010 << 2 >> 1 & 0xF), 0o17 + 0x1F + 0b11, 0xff, 10j)