Computer Science

Write the output of the following:

>>> x = "hello"
>>> print(x[1:-2])

Python

Python String Manipulation

2 Likes

Answer

el

Working

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".

Answered By

1 Like


Related Questions