ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
s = 'a1b2c3'
letters = ''.join(c for c in s if c.isalpha())
digits = sum(int(c) for c in s if c.isdigit())
print(letters, digits)
  1. A. abc 6
  2. B. abc 123
  3. C. a1b2c3 6
  4. D. abc 0

Correct answer: A. abc 6

isalpha keeps the letters and isdigit keeps the digits. The digits 1, 2 and 3 sum to 6.

More Python Programming questions

Exams that ask this topic