ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print(format(255, '08b'), format(255, '#x'), '{:>5}|{:<3}|'.format(42, 7))- A. 11111111 0xfe 42|7 |
- B. 11111111 0xff 42|7 |
- C. 11111111 0b11111111 42|7 |
- D. 11111111 0xff 7|42 |
Correct answer: B. 11111111 0xff 42|7 |
The 08b spec pads a binary string to 8 digits, and # with x adds the 0x prefix. Width 5 right-aligns 42 with three leading spaces, and 7 is left-aligned in width 3.
More Python Programming questions
- What is printed? python def max3(a): a = sorted(a) return max(a[-1] a[-2] a[-3], a[0] a[1] a[-1]) print(max3([1, 2, 3, 4]), max3([-10…
- What is printed? python def g(): try: yield 1 yield 2 finally: print('cleanup') it = g() print(next(it)) it.close() print(list(it))
- What is printed? python print('hello world'.translate({ord('l'): None, ord('o'): 'O'}))
- What is printed? python class N: def init(self, v): self.v = v self.nxt = None def hascycle(h): slow = fast = h steps = 0 while fast and…
- What is printed? python print(hash(-1), hash(-2), hash(-1) == -2, hash(1) == hash(1.0))
- What is printed? python print(232, (23)2, -22, (-2)2, 2-12)