ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(len('a1b22c333'.split('2')), ''.join(c for c in 'a1b22c333' if c.isdigit()), len('a1b22c333'))
  1. A. 3 122333 8
  2. B. 4 122333 9
  3. C. 3 122333 9
  4. D. 3 122 9

Correct answer: C. 3 122333 9

split('2') breaks the text at each 2, giving three pieces. Joining the digits gives 122333, and the full string has nine characters.

More Python Programming questions

Exams that ask this topic