ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(sum(1 for c in 'a1b22c333' if c.isdigit()), ''.join(c for c in 'a1b22c333' if c.isalpha()), int(''.join(c for c in 'a1b22' if c.isdigit())) + 1)
  1. A. 6 abc 122
  2. B. 5 abc 123
  3. C. 6 a1b 123
  4. D. 6 abc 123

Correct answer: D. 6 abc 123

Six characters are digits in 'a1b22c333', the letters are abc, and the digits of 'a1b22' form 122, which is 123 after adding one.

More Python Programming questions

Exams that ask this topic