What does the following code output?

ICSE Class 10 Robotics & AI PYQ · 2025 Specimen · Section A

1(xviii)1 Mark · 2025 · Section A · 2025 Specimen

What does the following code output?

string = "Hello World"
print(string[1:5])
Show SolutionHide Solution↓

"ello"

Reason — In Python, string slicing returns characters from the starting index up to the ending index minus one. Therefore, string[1:5] extracts the characters at index positions 1, 2, 3, and 4, which are e, l, l, and o, and hence the output is "ello".

← Previous questionNext question →

Browse the free Robotics & AI sample bank