ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print(sum(1 for c in 'a1 b2_' if c.isalpha()), sum(1 for c in 'a1 b2_' if c.isdigit()), sum(c.isspace() for c in 'a1 b2_'))
  1. A. 2 2 0
  2. B. 2 1 1
  3. C. 3 2 1
  4. D. 2 2 1

Correct answer: D. 2 2 1

Two letters, a and b, and two digits, 1 and 2, are present. The underscore is neither a letter nor a digit, and the space is the only whitespace.

More Python Programming questions

Exams that ask this topic