I have a text file which contains some lines as follows input text
guildenstern32_7
Nay, good my lord, this courtesy is **not** of the right breed.
If it shall please you to make me a wholesome answer, I will do
your mother's commandment: if **not**, your pardon and my return
shall be the end of my business.
guildenstern32_8
What, my lord?
guildenstern32_9
O my lord, if my duty be too bold, my love is too unmannerly.
guildenstern32_10
My lord, I cannot.
guildenstern32_11
Believe me, I cannot.
the code is as follows
file = open("file.txt", "r")
#read content of file to string
data = file.read()
#get number of occurrences of the substring in the string
occurrences = data.count('not')
print('Number of occurrences of the word :', occurrences)
file.close()
the output yields the occurrences as 4 but it has only to not's. It also considers cannot also. how to avoid that??