ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
s = '42'
print(s * 2 + '!' if s.isdigit() else '', int(s) * 2, s.zfill(4) + '|' + s.rjust(4, '0') + '|' + s.ljust(4, '0'))
  1. A. 4242! 84 0042|0042|0042
  2. B. 42!! 84 0042|0042|4200
  3. C. 4242! 84 0042|0042|4200
  4. D. 4242! 42 0042|0042|4200

Correct answer: C. 4242! 84 0042|0042|4200

The conditional expression applies to the first argument, so s * 2 + '!' is printed. zfill, rjust and ljust pad to four characters with zeros, using the left or right side as each method specifies.

More Python Programming questions

Exams that ask this topic