Python 教學

小訣竅

這份教學將非常規地介紹 Python 語言與系統的基本概念及功能。請注意,它預期你對程式設計有基本的了解。實際用 Python 直譯器進行實際操作將有助於學習,但所有範例都是獨立完整的,所以這份教學也可以離線閱讀。

Python 是一種易學、功能強大的程式語言。它有高效能的高階資料結構,也有簡單但有效的方法去實現物件導向程式設計。Python 優雅的語法和動態型別,結合其直譯特性,使它成為眾多領域和大多數平臺上,撰寫腳本和快速開發應用程式的理想語言。

使用者可以自由且免費地從 Python 官網上 (https://www.python.org/) 取得各大平台上用的 Python 直譯器和標準函式庫,下載其來源碼或二進位形式執行檔,同時,也可以將其自由地散佈。另外,Python 官網也提供了許多自由且免費的第三方 Python 模組、程式與工具、以及額外的文件。

使用 C 或 C++(或其他可被 C 呼叫的程式語言),可以很容易在 Python 直譯器內新增函式及資料型別。同時,對可讓使用者自訂功能的應用程式來說,Python 也適合作為其擴充語言 (extension language)。

This tutorial introduces the reader informally to the basic concepts and features of the Python language and system. Be aware that it expects you to have a basic understanding of programming in general. It helps to have a Python interpreter handy for hands-on experience, but all examples are self-contained, so the tutorial can be read off-line as well.

For a description of standard objects and modules, see The Python Standard Library. The Python Language Reference gives a more formal definition of the language. To write extensions in C or C++, read Extending and Embedding the Python Interpreter and Python/C API Reference Manual. There are also several books covering Python in depth.

This tutorial does not attempt to be comprehensive and cover every single feature, or even every commonly used feature. Instead, it introduces many of Python's most noteworthy features, and will give you a good idea of the language's flavor and style. After reading it, you will be able to read and write Python modules and programs, and you will be ready to learn more about the various Python library modules described in The Python Standard Library.

The Glossary is also worth going through.