CBSE Class 12 Computer Science
Question 40 of 120
Review of Python Basics — Question 14
Back to all questions2
Reason — The count() method in Python is used to count the occurrences of a substring within a string. In the given code, the string "xyyzxyzxzxyy" is searched for occurrences of the substring 'yy' starting from index 1 (the second position in the string). The substring 'yy' occurs twice in the specified range [1:] of the string "xyyzxyzxzxyy", at indices 1-2 and 10-11. Therefore, the count() method returns 2, indicating that 'yy' occurs twice in the specified range.