Strings · Class 11 · CBSE · Science Computer Science

What is printed by the following Python code? s = "banana"; print(s[1:6:2])

Practice question from Strings (Class 11 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.

medium · MCQ · Q-AE296D

What is printed by the following Python code? s = "banana"; print(s[1:6:2])

  1. A.ban
  2. B.aaaCorrect answer
  3. C.nna
  4. D.ana

Solution

The slice starts at index 1, stops before index 6, and takes every second character. It selects characters at indices 1, 3, and 5, producing "aaa".

More from Strings

All of Strings

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed