Skip to main content
 首页 » 编程设计

python : string contains NOT string in

2025年05月04日14lvdongjie

我正在寻找执行以下搜索的单行 Python 表达式:

targets = ['habble', 'norpouf', 'blantom'] 
entry = "Sorphie porre blantom nushblot" 
 
found=False 
for t in targets : 
    if t in entry : 
        found = True 
        break 
 
 
print ("found" if found else "not found") 

这样我们就可以写一些像这样的东西:

print("found" if entry.contains(targets) else "not found") 

请您参考如下方法:

您可以使用任何:

targets = ['habble', 'norpouf', 'blantom'] 
entry = "Sorphie porre blantom nushblot" 
result = 'found' if any(i in entry for i in targets) else 'not found'