What will be the output of the following Python code?

ICSE Class 10 Robotics & AI PYQ · 2026 Paper · Section A

2(ix)1 Mark · 2026 · Section A · 2026 Paper

What will be the output of the following Python code?

str1 = 'PYTHON'
print(str1[1:4])
Show SolutionHide Solution↓
YTH

The string 'PYTHON' is stored in the variable str1. Python uses 0-based indexing.

Index Table:

IndexCharacter
0P
1Y
2T
3H
4O
5N

The slice str1[1:4] selects characters from index 1 to 3 (excluding 4): YTH

Hence, the output is YTH.

← Previous questionNext question →

Browse the free Robotics & AI sample bank