所以我在寻找问题并遇到了这个最近的问题
答案很简单,但我注意到的一件事是它实际上确实返回了SPAM精确匹配
所以这段代码
text = 'buy now'
print(text == 'buy now' in text) # True
Run Code Online (Sandbox Code Playgroud)
返回True,我不明白为什么
我试图通过将括号放在不同的地方来找出答案
text = 'buy now'
print(text == ('buy now' in text)) # False
Run Code Online (Sandbox Code Playgroud)
返回False和
text = 'buy now'
print((text == 'buy now') in text) # TypeError
Run Code Online (Sandbox Code Playgroud)
提高TypeError: 'in <string>' requires string as left operand, not bool
我的问题是这里发生了什么以及为什么会这样?
聚苯乙烯
我在 Ubuntu 20.04 上运行 Python 3.8.10