In this program, we will take a string and substring as input and count occurrences of a substring in a string.
Steps to solve the program
- Take a string and substring as input.
- Count the occurrences of a substring in a string using count().
- Print the output.
#Input string
string = "sqatoolspythonspy"
sub = "spy"
#Printng output
string.count("spy")
Output :
2