pau*_*111 0 python string python-3.x
我构建了python代码,该代码可以找到下面另一个句子中的句子,但是效果不佳。
sentence = "While speaking to Ross, Rachel comes to terms with something that was bothering her."
if "Rachel has made coffee to Joey and Chandler for the first time of her entire life." or "Monica can't stop smiling while having a conversation with Rachel." in sentence:
print("YES")
else
print("NO!")
Run Code Online (Sandbox Code Playgroud)
应该打印"NO!"它,因为它的句子完全不同。但是,它打印"YES"..
这是因为弦吗?
我在代码中做错了什么吗?
我会误会吗?
您使用的方式不or正确-
if "Rachel has made coffee to Joey and Chandler for the first time of her entire life." in sentence or "Monica can't stop smiling while having a conversation with Rachel." in sentence:
Run Code Online (Sandbox Code Playgroud)
如果False变量为None或空列表,空字符串,空集或空字典(...),True则返回if条件,否则返回。