Python Strings · Question 7 · Easy

In the slice s[a:b] of a string s, with a less than b, which characters are included?

  1. Characters from index a up to index b
  2. Characters from index a up to index b - 1
  3. Characters from index a + 1 up to index b
  4. The first b characters after index a
Answer and explanation

Answer: B. Characters from index a up to index b - 1

Explanation: A slice includes the start index and excludes the stop index. So s[a:b] covers indexes a, a + 1, ... , b - 1, which is b - a characters.

Previous: An f-string is used to report Asha's marks. What exactly is printed? · Next: A slice with a step of 3 is taken from a city name. What does it print?

Practise python strings

Try a fresh set of python strings questions with an explanation after every answer, free and without signing up: Python Strings practice. Or sit a full placement mock test.

More python strings questions

More python practice

Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge