Notes_2_on <Learning Python>

wanderer 发表于 2008-05-25 10:47:15

Part III .Statements and Syntax

1.
Boolean and and or operators return a true or false operand object, not an integer 1 or 0:
    or returns left operand if it's true
    else return right operand(true or false)

    and returns left operand if it's false
    else return right operand(true or false)

2 < 3 ==> True or 1
2 or 3 ==> 2
'abc' or 'cde' ==> 'abc'

2 and 3 ==> 3
[] and {} ==> []
((1 and 2)or 3)

((A and B) or C) can be used to emulate an if/else statement

2.continue causes endless loop!:
i = 0
while i < 9:
    if i == 5:
        continue
    print i

3.
When combined with the loop else, the break statement can often eliminate the search status flags used in other language.(P158)

4.
Loop else is also run if the loop body is never executed.

5.(!!)
Sequence iteration is not under your control. Assignment target will be automatically set to the next item in the sequence.

for i in range(3):
    print i
    i += 2
==>
0
1
2
关键词(Tag): python

收藏: QQ书签 del.icio.us 订阅: Google 抓虾

最新评论

发表评论

* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 
 

分类小组论坛
杂谈, 娱乐、八卦, 文学、艺术, 体育, 旅游、同城, 象牙塔, 情感, 时尚、生活, 星座, 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定