我正在尝试在字符串中搜索单词。
例子
match = 'File'
s2 = 'name of File: is .jpg'
if match not in s2:
print 'ok'
它奏效了。我可以用 list
做到这一点吗?
match = ['File','Category']
最佳答案
当然可以。因此,我们检查 match
中的每个单词是否存在于 s2
中。
for word in match:
if word not in s2:
print 'ok'
或者一个简单的单行 -
[word for word in match if word not in s2]
关于python - 如何在字符串中搜索单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8455025/