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')
- 11 times
- 8 times
- 3 times
- 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
In Python string, + and * represent which of the following operations?
- Concatenation, Replication
- Addition, Multiplication
- Neither (i) nor (ii)
- Both (i) and (ii)
Which of following is not a valid string operation?
- Slicing
- Concatenation
- Repetition
- Floor
Which of the following is the correct syntax of String Slicing?
- String_name [start : end]
- String_name [start : step]
- String_name [step : end]
- String_name [step : start]
What is the correct Python code to display the last four characters of "Digital India"?
- str [-4 :]
- str [4 :]
- str [*4 :]
- str [/4 : ]