ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(f'{"x"!r}', '%s and %r' % ('x', 'x'), '{!s} {!r}'.format('x', 'x'))- A. x 'x' and x x y
- B. 'x' x and 'x' 'x' 'x' 'x'
- C. 'x' x and 'x' x 'x'
- D. 'x' x and x y 'x'
Correct answer: C. 'x' x and 'x' x 'x'
An f-string field with !r applies repr, so the quoted x comes first. %s prints x plainly while %r shows quotes, and str.format's !s prints x while !r shows 'x'.
More Python Programming questions
- What is printed? python s = 'abc' print(s 2 == 'abcabc', s[1:] + s[:1], s[-1:] + s[:-1], len('ab' 0))
- What is printed? python print(int('007'), int('-07'), int('01'), int('00'))
- What is printed? python print(float('1e3') == 1000, float('1E-2') 100, float(' .5 '), float('5.'))
- What is printed? python print('{0:.2%}'.format(0.12345), '{:,}'.format(1234), '{:e}'.format(0), '{:.0f}'.format(0.5))
- What is printed? python print(0.1 + 0.2 == 0.3 or 'no', 0.5 + 0.25 == 0.75 and 'yes')
- What is printed? python print(divmod(-7, 3), divmod(7, -3), divmod(-8.5, 4))