Strings · Class 11 · CBSE · Science Computer Science

What is printed by the following Python code? word = "Python"; print(word[-2])

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

easy · MCQ · Q-2A6C7E

What is printed by the following Python code? word = "Python"; print(word[-2])

  1. A.t
  2. B.h
  3. C.oCorrect answer
  4. D.n

Solution

Negative indexing counts characters from the end of a string. In "Python", index -2 refers to o.

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