30th May, 2008
Python Documentation - Conditional Expression
Guido van Rossum eventually chose a surprising syntax:
x = true_value if condition else true_fails
Evaluation is still lazy as in existing Boolean expressions, so the order of evaluation jumps around a bit
eg: content = ((doc + '\n') if doc else '')
# First version -- no parens
level = 1 if logging else 0
# Second version -- with parens
level = (1 if logging else 0)
parentheres(括号)
Kinghorses
阅读(1209) | 评论(0) | 转发(0) |