KnowledgeBoat Logo
|

Computer Science

Which of the following will give "Simon" as output?

str1 = "Hari,Simon,Vinod"
  1. print(str1[-7:-12])
  2. print(str1[-11:-7])
  3. print(str1[-11:-6])
  4. print(str1[-7:-11])

Python String Manipulation

1 Like

Answer

print(str1[-11:-6])

Reason — The correct statement to get "Simon" as output is print(str1[-11:-6]). In the string str1, the slice [-11:-6] extracts the substring starting from the character at index -11 (which is 'S' in "Simon") up to the character at index -5, thus resulting in "Simon".

Answered By

1 Like


Related Questions