ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(int('10', 2), int('0o17', 0), int('17', 8), int('0x_ff', 16))- A. 2 15 17 255
- B. 2 17 15 255
- C. 2 15 15 0
- D. 2 15 15 255
Correct answer: D. 2 15 15 255
int() with base 2 reads 10 as 2, and base 0 reads the 0o prefix as octal, so 17 octal is 15. Base 8 reads 17 as octal, and an underscore may follow the 0x prefix in int(), giving 255.
More Python Programming questions
- What is printed? python x = 0xDEAD print(x >> 8 & 0xFF, (x >> 8) & 0xF, hex(x & -x))
- What is printed? python print(sorted([-3, 2, -1, 4], key=lambda v: (abs(v) % 3, v)))
- What is printed? python print(f'{1234.5:,.2f}', f'{0.000123:.2e}', f'{-0.0:+.1f}', f'{0x123456:x}')
- What is printed? python print(int('٠٠٢٩') + 1, '٢٩'.isdigit())
- What is printed? python s = 'abc' print(s 0 == '', s[::-1][::-1] == s, s[1:-1] 2, s[-3:-1])
- What is printed? python print(sorted(['x10', 'x9', 'x1'], key=lambda s: int(s[1:])))