ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(int('0x1F', 16), int('1F', 16), int('0b101', 0), int(' 42 '), int('4_2'))- A. 31 31 5 42 4_2
- B. 31 31 0 42 42
- C. 31 31 5 42 42
- D. ValueError
Correct answer: C. 31 31 5 42 42
int() accepts a 0x prefix when the base is 16, underscores between digits in any base, and surrounding whitespace. The base-0 call infers the 0b prefix and reads 101 as 5.
More Python Programming questions
- What is printed? python print(int('٣') + 1)
- What is printed? python print(bin(10)[2:].zfill(8), format(-10, '08b'), format(-10 & 0xFF, '08b'), f'{255:#x}')
- What is printed? python print((1 << 70).bitcount(), (270 - 1).bitcount(), (-1).bitcount(), (-8).bitcount())
- What is printed? python print(f'{0.1:.20f}', f'{1e16:g}', f'{123456789.0:e}', f'{2.5:.0f}', f'{3.5:.0f}')
- What is printed? python n = float('nan') print(n in [n], [n] == [n], n == n, n is n)
- 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)