ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print('  x\t'.strip() == 'x', 'a\tb'.expandtabs(4), len('a\tb'.expandtabs(4)), 'ab\r\ncd'.splitlines())
  1. A. True a b 3 ['ab', 'cd']
  2. B. True a b 4 ['ab\r\ncd']
  3. C. True a b 5 ['ab', 'cd']
  4. D. False a b 5 ['ab', 'cd']

Correct answer: C. True a b 5 ['ab', 'cd']

strip() removes the tab, and expandtabs(4) pads the tab to the next column multiple of 4, which here is three spaces. splitlines() treats \r\n as one line break, so it returns two strings.

More Python Programming questions

Exams that ask this topic