Python 教學¶
小訣竅
這份教學是為了那些對 Python 語言有興趣的程式設計師而設計的,不是對於程式設計新手的入門教學。
Python 是一種易學、功能強大的程式語言。它有高效能的高階資料結構,也有簡單但有效的方法去實現物件導向程式設計。Python 優雅的語法和動態型別,結合其直譯特性,使它成為眾多領域和大多數平臺上,撰寫腳本和快速開發應用程式的理想語言。
The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python web site, https://www.python.org/, and may be freely distributed. The same site also contains distributions of and pointers to many free third party Python modules, programs and tools, and additional documentation.
使用 C 或 C++(或其他可被 C 呼叫的程式語言),可以很容易在 Python 直譯器內新增函式及資料型別。同時,對可讓使用者自訂功能的應用程式來說,Python 也適合作為其擴充語言 (extension language)。
這份教學將非常規地介紹 Python 語言與系統的基本概念及功能。請注意,它預期你對程式設計有基本的了解。實際用 Python 直譯器進行實際操作將有助於學習,但所有範例都是獨立完整的,所以這份教學也可以離線閱讀。
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.
- 1. Whetting Your Appetite
- 2. Using the Python Interpreter
- 3. An Informal Introduction to Python
- 4. More Control Flow Tools
- 4.1.
ifStatements - 4.2.
forStatements - 4.3. The
range()Function - 4.4.
breakandcontinueStatements - 4.5.
elseClauses on Loops - 4.6.
passStatements - 4.7.
matchStatements - 4.8. Defining Functions
- 4.9. More on Defining Functions
- 4.10. Intermezzo: Coding Style
- 4.1.
- 5. Data Structures
- 6. Modules
- 7. 輸入和輸出
- 8. 錯誤與例外
- 9. 類別
- 10. Brief Tour of the Standard Library
- 10.1. Operating System Interface
- 10.2. File Wildcards
- 10.3. Command Line Arguments
- 10.4. Error Output Redirection and Program Termination
- 10.5. String Pattern Matching
- 10.6. Mathematics
- 10.7. Internet Access
- 10.8. Dates and Times
- 10.9. Data Compression
- 10.10. Performance Measurement
- 10.11. Quality Control
- 10.12. Batteries Included
- 11. Brief Tour of the Standard Library --- Part II
- 12. Virtual Environments and Packages
- 13. What Now?
- 14. Interactive Input Editing and History Substitution
- 15. Floating-Point Arithmetic: Issues and Limitations
- 16. Appendix