1(xviii)
What does the following code output?
string = "Hello World" print(string[1:5])
- (a)"Hell"
- (b)"ello"
- (c)"World"
- (d)"Hello"
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".