Python 教學
***********

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

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

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

這份教學將簡介 Python 語言與系統的基本概念及功能。除了閱讀之外、實際用
Python 直譯器寫程式跑範例，將有助於學習。但如果只用讀的，也是可行的學
習方式，因為所有範例的內容皆獨立且完整。

若想了解 Python 標準物件和模組的描述，請參閱 Python 標準函式庫
(Standard Library)。在 The Python Language Reference 中，您可以學到
Python 語言更正規的定義。想用 C 或 C++ 寫延伸套件 (extensions) 的讀者
，請閱讀 Extending and Embedding the Python Interpreter 和 Python / C
API 參考手冊 。此外，市面上也能找到更深入的 Python 學習書。

這份教學中，我們不會介紹每一個功能，甚至，也不打算介紹完每一個常用功能
。取而代之，我們的重心將放在介紹 Python 中最值得一提的那些功能，幫助您
了解 Python 語言的特色與風格。讀完教學後，您將有能力閱讀和撰寫 Python
模組與程式，也做好進一步學習 Python 標準函式庫 (Standard Library) 中各
類型的 Python 函式庫模組的準備。

Glossary 頁面也值得細讀。

* 1. 淺嘗滋味

* 2. 使用 Python 直譯器

  * 2.1. 啟動直譯器

    * 2.1.1. 傳遞引數

    * 2.1.2. 互動模式

  * 2.2. 直譯器與它的環境

    * 2.2.1. 原始碼的字元編碼 (encoding)

* 3. 一個非正式的 Python 簡介

  * 3.1. 把 Python 當作計算機使用

    * 3.1.1. 數字 (Number)

    * 3.1.2. 字串 (String)

    * 3.1.3. List（串列）

  * 3.2. 初探程式設計的前幾步

* 4. 深入了解流程控制

  * 4.1. "if" 语句

  * 4.2. "for" 语句

  * 4.3. "range()" 函式

  * 4.4. "break" 和 "continue" 语句，以及循环中的 "else" 子句

  * 4.5. "pass" 语句

  * 4.6. 定義函式 (function)

  * 4.7. More on Defining Functions

    * 4.7.1. Default Argument Values

    * 4.7.2. Keyword Arguments

    * 4.7.3. Special parameters

      * 4.7.3.1. Positional-or-Keyword Arguments

      * 4.7.3.2. Positional-Only Parameters

      * 4.7.3.3. Keyword-Only Arguments

      * 4.7.3.4. Function Examples

      * 4.7.3.5. Recap

    * 4.7.4. Arbitrary Argument Lists

    * 4.7.5. Unpacking Argument Lists

    * 4.7.6. Lambda Expressions

    * 4.7.7. 說明文件字串

    * 4.7.8. Function Annotations

  * 4.8. Intermezzo: Coding Style

* 5. 資料結構

  * 5.1. 進一步了解 List（串列）

    * 5.1.1. 將 List 作為 Stack（堆疊）使用

    * 5.1.2. 將 List 作為 Queue（佇列）使用

    * 5.1.3. List Comprehensions（串列綜合運算）

    * 5.1.4. 巢狀的 List Comprehensions

  * 5.2. "del" 语句

  * 5.3. Tuples 和序列 (Sequences)

  * 5.4. 集合 (Sets)

  * 5.5. 字典（Dictionary）

  * 5.6. 迴圈技巧

  * 5.7. 更多條件式主題

  * 5.8. 序列和其他資料結構之比較

* 6. 模組

  * 6.1. More on Modules

    * 6.1.1. Executing modules as scripts

    * 6.1.2. The Module Search Path

    * 6.1.3. "Compiled" Python files

  * 6.2. Standard Modules

  * 6.3. The "dir()" Function

  * 6.4. Packages

    * 6.4.1. Importing * From a Package

    * 6.4.2. Intra-package References

    * 6.4.3. Packages in Multiple Directories

* 7. 輸入和輸出

  * 7.1. 更華麗的輸出格式

    * 7.1.1. 格式化的字串文本 (Formatted String Literals)

    * 7.1.2. The String format() Method

    * 7.1.3. Manual String Formatting

    * 7.1.4. Old string formatting

  * 7.2. Reading and Writing Files

    * 7.2.1. Methods of File Objects

    * 7.2.2. Saving structured data with "json"

* 8. 錯誤和例外

  * 8.1. 語法錯誤

  * 8.2. 例外

  * 8.3. 處理例外

  * 8.4. Raising Exceptions

  * 8.5. User-defined Exceptions

  * 8.6. Defining Clean-up Actions

  * 8.7. Predefined Clean-up Actions

* 9. Classes

  * 9.1. A Word About Names and Objects

  * 9.2. Python Scopes and Namespaces

    * 9.2.1. Scopes and Namespaces Example

  * 9.3. A First Look at Classes

    * 9.3.1. Class Definition Syntax

    * 9.3.2. Class Objects

    * 9.3.3. Instance Objects

    * 9.3.4. Method Objects

    * 9.3.5. Class and Instance Variables

  * 9.4. Random Remarks

  * 9.5. Inheritance

    * 9.5.1. Multiple Inheritance

  * 9.6. Private Variables

  * 9.7. Odds and Ends

  * 9.8. Iterators

  * 9.9. Generators

  * 9.10. Generator Expressions

* 10. Python 標準函式庫概覽

  * 10.1. 作業系統介面

  * 10.2. 檔案之萬用字元

  * 10.3. 命令列引數

  * 10.4. 錯誤輸出重新導向與程式終止

  * 10.5. 字串樣式比對

  * 10.6. 數學相關

  * 10.7. 網路存取

  * 10.8. 日期與時間

  * 10.9. 資料壓縮

  * 10.10. 效能量測

  * 10.11. 品質控管

  * 10.12. 標準模組庫

* 11. Brief Tour of the Standard Library --- Part II

  * 11.1. Output Formatting

  * 11.2. Templating

  * 11.3. Working with Binary Data Record Layouts

  * 11.4. Multi-threading

  * 11.5. Logging

  * 11.6. Weak References

  * 11.7. Tools for Working with Lists

  * 11.8. Decimal Floating Point Arithmetic

* 12. 虛擬環境與套件

  * 12.1. 簡介

  * 12.2. 建立虛擬環境

  * 12.3. 用 pip 管理套件

* 13. 現在可以來學習些什麼？

* 14. Interactive Input Editing and History Substitution

  * 14.1. Tab Completion and History Editing

  * 14.2. Alternatives to the Interactive Interpreter

* 15. 浮點數運算：問題與限制

  * 15.1. Representation Error

* 16. 附錄

  * 16.1. 互動模式

    * 16.1.1. Error Handling

    * 16.1.2. Executable Python Scripts

    * 16.1.3. The Interactive Startup File

    * 16.1.4. The Customization Modules
