value = true-expr if condition else false-expr
In [1]: x = 5
In [2]: 'Non-negative' if x >= 0 else 'Negative'
Out[2]: 'Non-negative'
In [1]: x = 5
In [2]: 'Non-negative' if x >= 0 else 'Negative'
Out[2]: 'Non-negative'
本文标题:三元表达式
本文链接:https://www.haomeiwen.com/subject/xutfhqtx.html
网友评论