Computer Science

What will be the output of the following code?

Str1= 'My name is Nandini '
Str2 = Str1[3:7]
strlen = len(Str2)
print(strlen)
  1. 4
  2. 14
  3. 24
  4. 34

Python String Manipulation

2 Likes

Answer

4

Reason — The slice Str1[3:7] extracts characters from index 3 to 6 of the string 'My name is Nandini ', which results in 'name'. The length of this substring is 4 characters. Thus, len(Str2) returns 4.

Answered By

3 Likes


Related Questions