Python的程序由包,模塊(即一個(gè)Python文件)和函數(shù)組成。包是由一系列模塊組成的集合。模塊是處理某一類問題的函數(shù)和類的集合。
包中必須至少含有一個(gè)__init__.py文件,該文件的內(nèi)容可以為空。用于標(biāo)識(shí)當(dāng)前文件夾是一個(gè)包。
>;>;>; x = int(raw_input("Please enter an integer: "))
>;>;>; if x < 0:
... x = 0
... print 'Negative changed to zero'
... elif x == 0:
... print 'Zero'
... elif x == 1:
... print 'Single'
... else:
... print 'More'
...
>;>;>; # Measure some strings:
... a = ['cat', 'window', 'defenestrate']
>;>;>; for x in a:
... print x, len(x)
...
cat 3
window 6
defenestrate 12
>;>;>; for i in range(3): print i, 'Pythons'
...
0 Pythons
1 Pythons
2 Pythons
>;>;>; x = 'spam'
>;>;>; while x:
... print x,
... x = x[1:]
...
spam pam am m
while <條件測試>;:
<語句>;
if <條件測試>;: break #現(xiàn)在跳出循環(huán),忽略else
if <條件測試>;: continue #現(xiàn)在轉(zhuǎn)到循環(huán)頂部
else:
<語句>; #如果沒有遇到break
更多建議: