I am on python 3.5 and want to find the matched words from a file. The word I am giving is awesome
and the very first word in the .txt
file is also awesome
. Then why addedWord
is not equal to word
? Can some one give me the reason?
myWords.txt
awesome
shiny
awesome
clumsy
Code for matching
addedWord = "awesome"
with open("myWords.txt" , 'r') as openfile:
for word in openfile:
if addedWord is word:
print ("Match")
I also tried as :
d = word.replace("\n", "").rstrip()
a = addedWord.replace("\n", "").rstrip()
if a is d:
print ("Matched :" +word)
I also tried to get the class of variables by typeOf(addedWord)
and typeOf(word)
Both are from 'str'
class but are not equal. Is any wrong here?