问题:在python中简单的if语句写法
解决:
a = 3
b = a and a or 4
b = (a == 3) and a or 4
此时b 为3,相当于下面的if语句
if a:
b = a
else:
b = 4
或:
b = a if a==3 else 4
问题:在python中简单的if语句写法
解决:
a = 3
b = a and a or 4
b = (a == 3) and a or 4
此时b 为3,相当于下面的if语句
if a:
b = a
else:
b = 4
或:
b = a if a==3 else 4