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])
- A.t
- B.h
- C.oCorrect answer
- D.n
Solution
Negative indexing counts characters from the end of a string. In "Python", index -2 refers to o.
More from Strings
- What is printed by the following Python code? s = "banana"; print(s[1:6:2])
- What is the output of the following Python code? s = "Mississippi"; print(s.count("s"), s.find("sip"))
- Explain string immutability in Python and show how to change the first character of the string "cat" to produce "bat".
- What is printed by the following Python code? s = " Data Science "; print(s.strip().replace(" ", "").lower())
Practise more Computer Science
Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.
Start practising freeFree to start · No credit card needed