ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print(len(set('aabbcc')), sorted(set('cba')), 'abc'.index('b') + 'abc'.count('b'))
  1. A. 2 ['a', 'b', 'c'] 2
  2. B. 3 ['c', 'b', 'a'] 2
  3. C. 3 ['a', 'b', 'c'] 1
  4. D. 3 ['a', 'b', 'c'] 2

Correct answer: D. 3 ['a', 'b', 'c'] 2

The set of letters in aabbcc has three members, and sorted gives a, b and c. index('b') is 1 and count('b') is 1, giving 2.

More Python Programming questions

Exams that ask this topic