Python没有三目运算符( ?: )
方法一: true_part if condition else false_part
>>> "Fire" if True else "Water"
'Fire'
>>> "Fire" if False else "Water"
'Water'
方法二:condition and true_part or false_part
>>> True and "Fire" or "Water"
'Fire'
>>> False and "Fire" or "Water"
'Water'
网友评论