python and or-11876896
类似三目表达式的用法:bool? a : b >>> a ='first'>>> b ='second'
>>>1and a or b # 等价于 bool = true时的情况
'first'
>>>0and a or b # 等价于 bool = false时的情况
'second'
>>> a =''
>>>1and a or b # a为假时,则出现问题
'second'
>>>(1andor)# 安全用法,因为不可能为假,至少有一个元素
''
>>>
页:
[1]