I am learning Object-oriented programming and I am having trouble with the parameter of "self".
Here is my code for analysing text.
class analysedText(object):
def __init__ (self, text):
formatted_text=text.replace(".","").replace("!","").replace(",","").replace("?","")
lower_text=formatted_text.lower()
self.fmtText=lower_text
def freqAll(self):
word_list=self.fmtText.split(' ')
dic={}
for i in set(word_list):
dic[i]=word_list.count(i)
return dic
def freqOf(self,word):
freqDict=self.freqAll()
if word in freqDict:
return freqDict[word]
else:
return 0
I just learned that self refers to instance of the class. However, I can't understand the meaning of self.fmtText
and self.freqAll()
. Can anyone give me a specific explanation, please? Thanks in advance!