DA
DealiAxy
2021年12月18日

Python中的三元表达式

一般语言的三元表达式都是这种形式: result = statement ? true : false // For examle result = a b ? a : b Python中的三元表达式比较特殊,用下面这种形式 result = true if statement else false # For example result = a if a b else b

未分类
221
1 分钟阅读
更新于 05-27

一般语言的三元表达式都是这种形式:

result = statement ? true : false

// For examle
result = a > b ? a : b

Python中的三元表达式比较特殊,用下面这种形式

result = true if statement else false

# For example
result = a if a > b else b