xxxxxxxxxx
pythonCopy#defining string and substring
str1 = "This dress looks good; you have good taste in clothes."
substr = "good"
#occurrence of word 'good' in whole string
count1 = str1.count(substr)
print(count1)
#occurrence of word 'good' from index 0 to 25
count2 = str1.count(substr,0,25)
print(count2)
xxxxxxxxxx
string = "Hello world!"
character = "l"
occurrence = string.count(character) # give 3