gpt4 book ai didi

Python OR 运算符和括号

转载 作者:太空宇宙 更新时间:2023-11-04 08:08:00 24 4
gpt4 key购买 nike

<分区>

示例 1 - 这有效:

def thisorthat():
var = 2

if (var == 3 or var == 2):
print "i see the second value"
elif (var == 2 or var == 15):
print "I don't see the second value"

thisorthat()

示例 2 - 这不起作用:

def thisorthat():
var = 2

if var == (3 or 2):
print "i see the second value"
elif var == (2 or 15):
print "I don't see the second value"

thisorthat() # "I don't see the second value"

有没有一种方法可以将变量与“或”运算符进行比较,而无需在每一行中重复变量两次?

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