CBSE Class 11 Computer Science Question 7 of 19

Strings in Python — Question 4

Back to all questions
4
Question

Question 4

Write the output of the following:

>>> x = "hello"
>>> print(x[1:-2])
Answer
Output
el
Explanation

The statement x[1:-2] slices the string "hello" starting from index 1 up to index -3. This results in the substring "el", so print(x[1:-2]) outputs "el".