ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
s = 'abc'
t = s * 2
print(t[::2], t[1::3], t.find('ca'), t.count('b'))
  1. A. acb bc -1 2
  2. B. ac bb 2 1
  3. C. acb ab 2 2
  4. D. acb bb 2 2

Correct answer: D. acb bb 2 2

t is 'abcabc'. Its even indices give 'acb'. [1::3] takes indices 1 and 4, which are both 'b', so it gives 'bb'. 'ca' starts at index 2, and 'b' appears twice.

More Python Programming questions

Exams that ask this topic