ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
s = 'abc' * 2
print(s.count('a'), s.index('c'), s[2::3], len(s.split('b')))
  1. A. 2 5 cc 3
  2. B. 2 2 c 3
  3. C. 2 2 cc 2
  4. D. 2 2 cc 3

Correct answer: D. 2 2 cc 3

abcabc has two a characters, and the first c is at index 2. The slice from index 2 with step 3 takes indices 2 and 5, both c. Splitting on b gives three pieces.

More Python Programming questions

Exams that ask this topic