ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = 255
print(f'{x:x}', f'{x:08b}', f'{x:o}', f'{x:#06x}')- A. ff 11111111 377 0x00ff
- B. ff 11111111 377 0x00ee
- C. ff 11111111 377 0xff
- D. ff 255 377 0x00ff
Correct answer: A. ff 11111111 377 0x00ff
x in hex is ff and 08b pads the binary to eight digits. Octal 255 is 377. The # flag adds the 0x prefix, and 06 pads the whole string including the prefix to six characters.
More Python Programming questions
- What is printed? python print(3 in {1: 'a', 3: 'b'}, '3' in {1: 'a', 3: 'b'}, 3 in [1, 3], 3 in range(3, 4))
- What is printed? python print(list(zip('ab', 'cd', 'ef'))[1], dict(zip('ab', [1])))
- What is printed? python print(len('héllo'), len('héllo'.encode('utf-8')), 'é'.encode('utf-8'))
- What is printed? python import math print(math.floor(7 / 2) 2 + 7 % 2, 7 // 2 2 + 7 % 2)
- What is printed? python x = [0] 3 x[0] += 1 x = x 2 x[3] += 5 print(x)
- What is printed? python from collections import Counter c = Counter('aab') c.subtract('ab') print(c['a'], c['b'], sorted((+c).items()))