gpt4 book ai didi

python - 括号对 Python 中的 'or' 运算符有什么影响?

转载 作者:太空狗 更新时间:2023-10-30 01:39:31 24 4
gpt4 key购买 nike

python中这两个语句有区别吗:

if tag == ('/event' or '/organization' or '/business'):

if tag == '/event' or '/organization' or '/business':

最佳答案

他们都错了。你需要的是:

if tag == '/event' or tag == '/organization' or tag == '/business':

或:

if tag in ['/event', '/organization', '/business']:

关于python - 括号对 Python 中的 'or' 运算符有什么影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5791031/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com