Computer Science

How many times is the word "Python" printed in the following statement?

s = 'I love Python'
for ch in s[3:8]:
    print('Python')
  1. 11 times
  2. 8 times
  3. 3 times
  4. 5 times

Python String Manipulation

1 Like

Answer

5 times

Reason — The slice s[3:8] consists of 5 characters, and the for loop prints 'Python' for each character in the substring, resulting in 'Python' being printed 5 times.

Answered By

2 Likes


Related Questions