方法一
'a' if 0==0 else 'b'
# 'a'
'a' if 1==0 else 'b'
# 'b'
方法二
(0==0) and 'a' or 'b'
# 'a'
(1==0) and 'a' or 'b'
# 'b'
方法三
['a', 'b'][0==0]
# 'b'
['a', 'b'][1==0]
# 'a'
a = []
b = []
print(a is b)
# False
None
c = None
print(c is None)
# True
2 in [2,3]
# True
4 in [2,3]
# False
any([0,0,0])
# False
any([0,0,1])
# True
any([0,1,1])
# True
any([1,1,1])
# True
實際應用:
a = [1,2,3]
any(e == 1 for e in a)
# True