ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print('%s|%r' % ("it's", "it's"))- A. it's|"its"
- B. it's|"is"
- C. it's|"it's"
- D. its|"it's"
Correct answer: C. it's|"it's"
%s uses str() and shows the text as-is, while %r uses repr(), which wraps a string that contains a single quote in double quotes. That is why the second part shows the quotes.
More Python Programming questions
- What is printed? python print(ord('a') - ord('A'), chr(ord('A') + 32), 'Z'.lower() < 'a', 'z' > 'Z')
- What is printed? python print('-'.join('abc'), ''.join(map(str, [1, 2, 3])) == '123', ','.join([]) == '', 'x'.join(['', '']))
- What is printed? python s = 'hello' print(s.find('l'), s.index('l', 3), s.rfind('l'), s.count('ll'), s.find('z'))
- What is printed? python print('%.2e' % 0.000123456, '%G' % 1e-5, '%g' % 1e-5, '%.3g' % 1234.5)
- What is printed? python print(max(3, 3.0), min(3.0, 3), max([2, 2.0]), type(max(2.0, 2)).name)
- What is printed? python print(sum([True, True, False]), sum([1.5, True]), True 3 + 0.5, sum([1, 2], 10))