【发布时间】:2020-12-28 17:37:35
【问题描述】:
我有一个 python 脚本,我应该检查一个用破折号分隔的句子中是否存在两个单词
test_dash_sentence="wordtest-wordtest-word3-word4"
if ("word1" and "word2") or ("word1" and "word3") in test_dash_sentence:
print("FOUND")
else:
print("NOT FOUND")
我遇到的问题是即使word1 不存在也返回“找到”,所以它应该返回“未找到”
我尝试了不同的模型(用简单的引号,不带括号),如果我只在句子中查找一个单词似乎可以工作,但是当我查找两个单词时,它就不起作用了。
【问题讨论】:
-
@PM77-1 不完全是,因为在您的链接中,他们在字符串中查找 a 或 b 或 c,而我查找 a 和 b
ora 和 c
标签: python python-3.x if-statement operators