Chinaunix首页 | 论坛 | 博客
  • 博客访问: 152173
  • 博文数量: 11
  • 博客积分: 1198
  • 博客等级: 少尉
  • 技术积分: 335
  • 用 户 组: 普通用户
  • 注册时间: 2005-03-10 11:48
文章分类

全部博文(11)

文章存档

2013年(2)

2012年(1)

2010年(2)

2009年(4)

2008年(2)

我的朋友

分类: Python/Ruby

2008-05-30 14:06:51

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
 
 
 
阅读(1177) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~