我有以下代码:
file = open('AdjectivesList.txt', 'r')
lines = file.readlines()
file.close()
for word in words:
wordLowercase = word.lower()
for x, lol in enumerate(lines):
gg = (lines[x].lower())
if wordLowercase == gg:
print('identified')
即使wordLowercase
等于gg
,也不会打印字符串“identified”。为什么会这样?你知道吗
.readlines()
在文本文件的每一行末尾都包含换行符。这很可能是你的问题的原因。可以使用.strip()
删除换行符(以及字符串左右两侧的任何空格字符)。你知道吗参考
相关问题 更多 >
编程相关推荐