Python 模組【基礎學習】__Python

來源:互聯網
上載者:User

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()

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.