Jesse's Blog » 日志 » Notes_2_on <Learning Python>
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
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
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
