【问题标题】:Why always the same answer using != In python为什么在 python 中使用 != 总是相同的答案
【发布时间】:2022-07-26 23:12:23
【问题描述】:

当我用python写这个时,它只能给我同样的答案。谁能帮忙??

today = 'Saturday'

if today!='Sunday' or today!='Saturday':
    print('Rest')

else:

print('Work')

输出

Rest

【问题讨论】:

  • 使用| 而不是or

标签: python output


【解决方案1】:

如果两个(或多个)条件中的至少一个为真,则运算符“或”返回真,因此如果您希望所有条件都为真 - 使用运算符“和”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-15
    • 2011-10-26
    相关资源
    最近更新 更多