I'm trying to count letters inside a string using the .count
function, the strings are stored inside a list and the count function is a different function inside a class.
For some reason the .count
function will always give 0
in my code, and I can't seem to figure out why.
Class:
class string():
def __init__(self, sentence):
self.__s = sentence
def setSentence(self, sentence):
self.__s = sentence
def getSentence(self):
return self.__s
def count(self):
return self.__s.count("A")
Main:
if __name__ == '__main__':
sentences = ["AABBA", "AAAAB", "BABBB"]
x = string(sentences)
for index in x.getSentence():
print(x.count())
I was wondering if there's a way to use the .count
function without putting the sentence's in the parameters of count()