Python读书笔记-第五章

来源:互联网 发布:石家庄 软件开发培训 编辑:程序博客网 时间:2024/06/06 00:30
第五章
import
别名  from somemodule import some as abc
赋值: x,y,z=1,2,3
交换:x,y=y,x
字典:key,value={'name':'hello'}.popitem()
空无都是假False
比较表达式
x==y 
x<y
x!=y
x is y
x is not y
x in y
x not in y
断言
>>>age=-1
>>>assert 0<age<100 , 'some thing wrong'
循环
for x in y: something  ,  while x比较y :something  
特殊: for x in range(0,10) : somtthing
for key,value in d.items(): ...
其他:
zip压缩
sorted
reversed
跳出循环: break continue
for ...:
else : #仅在没有调用break的时候用
列表推倒
[(x,y) for x in range(3) for y in range(3)]

动态执行语句
exec "可以是赋值语句"
eval "求值"






0 0