为什么我的代码底部的if
声明不起作用? 单词列表包含几个“测试”,但在if
声明下方的打印语句不起作用。为什么我的if语句不起作用?
text1 = "a"
text2 = "b"
text3 = "c"
words = []
if len(text1) < 2:
words.append('test11')
elif text1.isspace():
words.append('test12')
if len(text2) < 2:
words.append('test21')
elif text2.isspace():
words.append('test22')
if len(text3) < 2:
words.append('test31')
elif text3.isspace():
words.append('test32')
if "test" in words:
print "Test"
你'if'声明是工作的罚款。没有任何内容被打印出来,因为你的清单“words”不包含字符串“test”。 – timgeb
“词”列表中不包含确切的单词'“test”'。可能是你用字符串 – kuro
混淆了这个,因为''test''不在'单词'中,它在单词的一些单词中,而不是单词本身。你可以使用:'如果有的话([“用单词测试”)''。虽然这有点罗嗦。 –