Robotics & Artificial Intelligence

What would be the output of following code …………… .

str1 = "Hello India"
s1 = str1[1:3]
print(s1) 
  1. He
  2. el
  3. Hlo
  4. None of these

Python String Manipulation

2 Likes

Answer

el

Reason — In Python, string indexing starts from 0. The slice operator [1:3] returns the characters from index 1 up to index 2 (end index is excluded), therefore the output is el.

Answered By

3 Likes


Related Questions