擅长:python、mysql、java
<p>以前,您在文件变量中搜索,该变量为“open(“search.txt”)”,由于该变量不在您的文件中,因此您得到的是word not found。</p>
<p>您还询问搜索词是否与“open(“search.txt”)”完全匹配,因为==。不要使用=,而是使用“in”。尝试:</p>
<pre><code>file = open("search.txt")
strings = file.read()
print(strings)
search_word = input("enter a word you want to search in file: ")
if(search_word in strings):
print("word found")
else:
print("word not found")
</code></pre>