python Module(模組)
在電腦開發的過程中,隨著程式碼越寫越多,在一個檔案裡代碼就會越來越長,越來越不容易維護。
為了編寫可維護的代碼,我們把很多函數分組,分別放到不同的檔案裡,這樣,每個檔案包含的代碼就相對較少,很多程式設計語言都採用這種組織代碼的方式。在Python中,一個.py檔案就稱之為一個模組(Module)。
使用模組有什麼好處呢。
最大的好處是大大提高了代碼的可維護性。其次,編寫的代碼不必從零開始。當一個模組編寫,就可以被其他地方引用。我們在編寫程式的時候,也經常引用其他模組,包含Python內建的模組和來自第三方的模組。
使用模組還可以避免函數名和變數名衝突。相同名字的函數和變數完全可以分別存在不同的模組中。
python內建函數:
|
Built-in Functions |
|
|
| abs() |
divmod() |
input() |
open() |
staticmethod() |
| all() |
enumerate() |
int() |
ord() |
str() |
| any() |
eval() |
isinstance() |
pow() |
sum() |
| basestring() |
execfile() |
issubclass() |
print() |
super() |
| bin() |
file() |
iter() |
property() |
tuple() |
| bool() |
filter() |
len() |
range() |
type() |
| bytearray() |
float() |
list() |
raw_input() |
unichr() |
| callable() |
format() |
locals() |
reduce() |
unicode() |
| chr() |
frozenset() |
long() |
reload() |
vars() |
| classmethod() |
getattr() |
map() |
repr() |
xrange() |
| cmp() |
globals() |
max() |
reversed() |
zip() |
| compile() |
hasattr() |
memoryview() |
round() |
__import__() |
| complex() |
hash() |
min() |
set() |
|
| delattr() |
help() |