Python newbie here. I am writing a program to count how many times a substring is a string, but keep receiving the error message: TypeError: a is undefined. I have looked at /googled similar threads but the code is usually convoluted and hard to follow.
Here is my code:
def stringcount(char, word):
for eachChar in word:
if char==eachChar:
count=count+1
return count
print count
stringcount('a', 'apple')
Thanks a lot!
counton string, e.g. 'apple'.count('a')countbefore assigning it a value, so you'll getUnboundLocalError.