ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
s = 'aAbBcC'
print(s.lower().count('a') + s.upper().count('A'), s.swapcase(), ''.join(c for c in s if c.islower()))
  1. A. 2 AaBbCc abc
  2. B. 4 AaBbCc abc
  3. C. 4 aAbBcD abc
  4. D. 4 AaBbCc abd

Correct answer: B. 4 AaBbCc abc

After lower() the string has two a's, and after upper() it has two A's, giving 4. swapcase flips every letter's case, and the generator keeps only the lowercase letters.

More Python Programming questions

Exams that ask this topic