Python Strings · Question 2 · Easy

The length of a string is used to reach its last character. What is printed?

s = "Pune"
print(len(s), s[len(s) - 1])
  1. 4 n
  2. 4 e
  3. 3 e
  4. IndexError
Answer and explanation

Answer: B. 4 e

Explanation: "Pune" has 4 characters at indexes 0 to 3. The last index is len(s) - 1 = 3, which holds 'e'. Using s[len(s)] instead would raise IndexError.

Previous: A city name is indexed from the front and from the back. What does this print? · Next: Two case-changing methods are called on string literals. What is the output?

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