Python Strings · Question 1 · Easy

A city name is indexed from the front and from the back. What does this print?

s = "Kolkata"
print(s[0], s[-2])
  1. K a
  2. o t
  3. K at
  4. K t
Answer and explanation

Answer: D. K t

Explanation: Indexing starts at 0, so s[0] is 'K'. Negative indexes count from the end: s[-1] is 'a' and s[-2] is 't'.

Next: The length of a string is used to reach its last character. What is 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