Read Python 2.5 documentant - What is new 1th
时间:2008-05-30 来源:kai0200
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
level = 1 if logging else 0
# Second version -- with parens
level = (1 if logging else 0) parentheres(括号) Kinghorses
相关阅读 更多 +