How to write a program that prints the number of times a particular string appears in a given word. For example: if I'm looking for the string 'dad' in a word 'asdadgfrdad' output should be 2.
def numStrings(a):
strings = 'dad'
result = 0
for char in a:
if char in strings:
result = result + 1
print result
numStrings("asdadgfrdad")
But this gives me the number of times the letters d,a are present in the given word. How to correct this?
snake_case
instead ofcamelCase
.