ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(f'{1:>{3}}', '{0[1]}-{1!r}'.format('ab', 'cd'), '{0!r:>6}'.format('x'), '{:.1%}'.format(0.256))- A. 1 b-'cd' 'x' 25.7%
- B. 2 b-cd 'x' 25.6%
- C. 1 b-'cd' 'x' 25.60%
- D. 1 b-'cd' 'x' 25.6%
Correct answer: D. 1 b-'cd' 'x' 25.6%
{0[1]} indexes the second character of the first argument, while !r applies repr to the second argument. The :>6 spec right-aligns the repr 'x' in six columns, and the percent format multiplies by 100 with one decimal.
More Python Programming questions
- What is printed? python x = 232 + 5 print((x 0x9E3779B1) & 0xFFFFFFFF, (5 0x9E3779B1) & 0xFFFFFFFF)
- What is printed? python import math print(math.factorial(20) // 106 % 1000, len(str(math.factorial(30)))…
- What is printed? python print(float('0.1') == 0.1, float(' 0.1 ') == 0.1, 0.1 == float(str(0.1)), 1e23 == 1023)
- What is printed? python total = 0 for s in ['10', '9', ' x', '+7', '10']: try: total += int(s) except ValueError: total -= 1 print(total)
- What is printed? python print('%d' % 3.9, '%d' % -3.9, '%.0f' % 0.5, '%i' % True)
- What is printed? python s = 'héllo' print(s[1], s.encode('latin-1')[1], len(s.encode('utf-16-le')), s.isascii())