ProgrammingVery hardCapgemini · Python · Advanced
What is printed?
What is printed?
print(f"{255:#x} {255:08b} {3.14159:.2f} {'ab':>4}|{12345.678:,.1f}")- A. 0xff 11111111 3.14 ab |12,345.7
- B. 0xff 11111111 3.14 ab|12,345.7
- C. 0xff 0b11111111 3.14 ab|12,345.7
- D. 0xff 11111111 3.14 ab|12345.7
Correct answer: B. 0xff 11111111 3.14 ab|12,345.7
#x adds the 0x prefix; 08b is zero-padded binary without a prefix; >4 right-aligns; ',.1f' adds a thousands separator and rounds to one decimal.
More Python Programming questions
- What is printed? python def fib(n, memo={}): if n < 2: return n if n not in memo: memo[n] = fib(n - 1) + fib(n - 2) return memo[n]…
- What is printed? python class T: def init(self, n): self.n = n def enter(self): print('in', self.n, end=' ') return self def exit(self…
- What is printed? python a = [1, 2, 3] a[1:2] = a a.insert(-1, 'x') a.insert(99, 'y') print(a, a.pop(-2), a.index(3))
- What is printed? python print(True + True, sum([True, False, True]), isinstance(True, int), [10, 20, 30][True], 'ab' False == '')
- What is printed? python class Meta(type): def new(m, name, bases, d): d['tag'] = name.lower() return super().new(m, name, bases, d) class…
- What is printed? python print(type(10 / 5))