Computer Science · Python String Slicing
Consider the following Python snippet: s = 'Computer Science' print(s[20]) print(s) What is the precise difference in behavior between Statement A (the first print) and Statement B (the second print)?
- 1Both statements raise an IndexError because the index is out of range.
- 2Statement A returns an empty string '', while Statement B raises an IndexError.
- 3Statement A raises an IndexError, while Statement B returns 'cience' by handling out-of-bound indices gracefully.✓
- 4Both statements execute successfully; Statement A returns the last character, and B returns the substring.
Correct answer
Statement A raises an IndexError, while Statement B returns 'cience' by handling out-of-bound indices gracefully.
Download Single Question PDF
Save this question and verified answer as a clean study sheet with live clickable link.
Share with Friends & Study Groups
Challenge your peer aspirants on WhatsApp or Telegram to solve this question!
Preparing for Computer Science?
Practice full-length mock tests with real exam timers, instant score analysis, and all-India ranking.
Want more practice questions on Python String Slicing?
Solve complete topic-wise tests with detailed solutions on GkGet.
Related Practice Questions
Recommended practice questions in Computer Science · Python String Slicing