Python Strings · Question 8 · Medium

A slice with a step of 3 is taken from a city name. What does it print?

s = "hyderabad"
print(s[1:8:3])
  1. yra
  2. heb
  3. yde
  4. yr
Answer and explanation

Answer: A. yra

Explanation: The slice starts at index 1 and takes every third index below 8: indexes 1, 4 and 7. Those characters are 'y', 'r' and 'a'.

Previous: In the slice s[a:b] of a string s, with a less than b, which characters are… · Next: replace() is called on a string and both the old and new names are printed…

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