ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print('%s' % [1, 'a'], '%r' % 'a', '%5.2s|' % 'hello', '%c' % 65)- A. [1, 'a'] 'a' he| A
- B. [1, 'a'] 'a' he| 65
- C. [1, 'a'] 'a' hel| A
- D. [1, 'a'] 'a' he| B
Correct answer: A. [1, 'a'] 'a' he| A
%s uses str() of the list, and %r uses repr() of the string. %5.2s keeps two characters and pads them to width five, and %c turns the integer 65 into the character A.
More Python Programming questions
- What is printed? python print(hash(1.5) == hash(3/2), hash(True) == hash(1), {0: 'x', False: 'y'}, len({1: 'a', True: 'b', 1.0: 'c'}))
- What is printed? python print(min(3, 2.0, True), max(1, 1.0), max(1.0, 1))
- What is printed? python print(253 == float(253), 253 + 1 == float(253 + 1), 253 + 2 == float(253 + 2))
- What is printed? python s = 'atbnc' print(len(s), s.split(), s.split('n'), repr(s.split()[0]))
- What is printed? python from fractions import Fraction print(Fraction(3, 6), Fraction('0.75'), Fraction(0.75), Fraction(1, 3) +…
- What is printed? python print(divmod(7, 2.5), divmod(-7.5, 2))