Python学习第三天

迭代器和列表解析

1.对象引用计数场景分析:

1)对象创建时

2)将对象添加进容器时,如list.append

3)当对象被当作参数传给函数时,也会添加计数

如:s1 = s2 = s3 = "abc" 这样的情景称为多重赋值,也会增加引用计数

减少引用计数:

1)引用对象的变量名被显式销毁

2)给引用此对象的某变名被设定为引用了其它对象,

3)从某个容器中移出对象时,如list.pop(),list.remove()等等

4)容器本身被销毁

2.流程控制语句

if boolean_expression:

    ...

elif boolean_expression:

    ...

else:

    ...

2) while

while boolean_expression:

while_suite

if boolean_expression:continue

if boolean_expression:break

else:

    else_suite

3)for

for expression in object:

    for_suite

    if boolean_expression:continue

    if boolean_expression:break

  else:

else_suite

 

posted @ 2016-10-27 19:08  今夕何年  阅读(126)  评论(0)    收藏  举报