返回顶部

收藏

Introducing or

更多
print 'a' or 'b'                                         

print '' or 'b'                                          

print '' or [] or {}                                     

def sidefx(): 
     print 'in sidefx()' 
     return 1 
'a' or sidefx()                                    

#If any value is true, or returns that value immediately. 
#In this case, 'a' is the first true value.

#or evaluates '', which is false, then 'b', which is true, and returns 'b'.

#If all values are false, or returns the last value. or evaluates '', 
#which is false, then [], which is false, then {}, which is false, and returns {}.

#Note that or evaluates values only until it finds one that is true in a boolean 
#context, and then it ignores the rest. 

标签:Python,基础

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2012-11-05 21:59:42java获得随机数代码 by 怪兽狂殴奥特曼
  2. 2014-07-21 21:35:32深度优先遍历嵌套容器 by 西国の海妖
  3. 2014-08-01 12:52:31secure crt 脚本 by 阮小七
  4. 2014-08-24 18:26:32批量修改cisco交换机密码 by 阮小七
  5. 2012-11-12 09:42:50python里简洁的条件语句写法替代?表达式 by JoanneTou
  6. 2014-10-20 15:58:50双倍超立方数 by Solon.Ring
  7. 2014-11-03 14:11:44Python unicode码转utf8 by 风云轩
  8. 2014-12-04 12:42:47ip地址转换成整数 by 蟋蟀MM
  9. 2015-11-27 16:36:34If statement: a dictionary-based 'switch' by 阮小七
  10. 2016-01-02 14:03:59While with else by xwz
  11. 2016-02-17 09:15:31Formatted print: float by 张宋付

发表评论