0

我正在使用 Python 来尝试检查字符串是否包含某些单词。它可以包含所有或部分单词。

listCall = ('Azura', 'Fly', 'yellow')
readME = 'the color is yellow'
if listCall in readME:
    print 'we found certain words'
else:
    print 'all good'
4

1 回答 1

2

您正在测试 *整个列表listCall* is inreadME 是否。您需要测试单个单词

if any(word in readME for word in listCall):

这使用生成器表达式和any()函数来有效地测试字符串中listCall的单个单词。readME

于 2015-02-08T01:25:21.840 回答