import somemodule | 導入模塊 |
from somemodule import somefuction | 導入函數 |
import math as foobar | 導入模塊,並使用別名 |
from math import sqrt as foobar | 導入函數,並使用別名 |
>>> x,y,z=1,2,3 >>> print x,y,z 1 2 3 >>> x,y=y,x >>> print x,y,z 2 1 3 >>> scoundrel={"name":"Robin"} >>> key, value = scoundrel.popitem() >>> print key, value name Robin
語句塊:在連續代碼行前同等放置數量的空格或者tab,表示語句塊;冒號(:)表示語句塊的開始,當回退到和已經閉合的塊同樣的縮緊是,表示當前塊結束python
條件和條件語句:布爾表達式中False,None,0,'',(),[],{}被視爲假(false),其餘一切被視爲真函數
布爾值:Ture,False工具
if語句學習
num=0 if num > 0: print "positive" elif num < 0: print "negative" else: print "zero"
布爾運算:and,or, notspa
while循環: while 條件: 條件爲True時候執行code
x=1 while x < 100: print x x += 1
numbers = [0,1,2,3,4,5,6,7,8,9] for number in numbers: print number for number in range(1,10): print number d={"x":1,"y":2, "z":3 } for key, value in d.items(): print key, value
一些迭代器工具對象
reversed:返回反轉後的結果,做用於序列或可迭代的對象 排序
跳出循環ip
continue:結束當前循環字符串