The Python Tutorial

Python 教程

Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.
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.
Python 解释器及丰富的标准库以源码或机器码的形式提供,可以到 Python 官网 https://www.python.org/ 免费获取适用于各个主要系统平台的版本,并可自由地分发。这个网站还包含许多免费第三方 Python 模块、程序和工具以及附加文档的发布页面或链接。

The Python interpreter is easily extended with new functions and data types implemented in C or C++ (or other languages callable from C). Python is also suitable as an extension language for customizable applications.
Python 解释器易于扩展,可以使用 C 或 C++(或者其他可以通过 C 调用的语言)扩展新的功能和数据类型。Python 也可用于可定制化软件中的扩展程序语言。

This tutorial introduces the reader informally to the basic concepts and features of the Python language and system. 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.
这个教程非正式地介绍 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.
有关标准的对象和模块,参阅 Python 标准库。Python 语言参考 提供了更正式的语言参考。想要编写 C 或者 C++ 扩展可以参考 扩展和嵌入 Python 解释器和 Python/C API 参考手册。也有不少书籍深入讲解Python 。

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.
这个教程并没有完整包含每一个功能,甚至常用功能可能也没有全部涉及。这个教程只介绍 Python 中最值得注意的功能,也会让你体会到这个语言的风格特色。学习完这个教程,你将可以阅读和编写 Python 模块和程序,也可以开始学习更多的 Python 库模块,详见 Python 标准库。

The Glossary is also worth going through.
术语对照表 也很值得阅读一下。

• 1. Whetting Your Appetite
• 1. 课前甜点

• 2. Using the Python Interpreter
• 2. 使用 Python 解释器

* 2.1. Invoking the Interpreter
• 2.1. 调用解释器

* 2.1.1. Argument Passing
• 2.1.1. 传入参数

* 2.1.2. Interactive Mode
• 2.1.2. 交互模式

* 2.2. The Interpreter and Its Environment
• 2.2. 解释器的运行环境

* 2.2.1. Source Code Encoding
• 2.2.1. 源文件的字符编码

• 3. An Informal Introduction to Python
• 3. Python 的非正式介绍

* 3.1. Using Python as a Calculator
• 3.1. Python 作为计算器使用

* 3.1.1. Numbers
• 3.1.1. 数字

* 3.1.2. Strings
• 3.1.2. 字符串

* 3.1.3. Lists
• 3.1.3. 列表

* 3.2. First Steps Towards Programming
• 3.2. 走向编程的第一步

• 4. More Control Flow Tools
• 4. 其他流程控制工具

* 4.1. "if" Statements
• 4.1. "if" 语句

* 4.2. "for" Statements
• 4.2. "for" 语句

* 4.3. The "range()" Function
• 4.3. "range()" 函数

* 4.4. "break" and "continue" Statements, and "else" Clauses on Loops
• 4.4. "break" 和 "continue" 语句,以及循环中的 "else" 子句

* 4.5. "pass" Statements
• 4.5. "pass" 语句

* 4.6. Defining Functions
• 4.6. 定义函数

* 4.7. More on Defining Functions
• 4.7. 函数定义的更多形式

* 4.7.1. Default Argument Values
• 4.7.1. 参数默认值

* 4.7.2. Keyword Arguments
• 4.7.2. 关键字参数

* 4.7.3. Special parameters
• 4.7.3. Special parameters

* 4.7.3.1. Positional-or-Keyword Arguments
• 4.7.3.1. Positional-or-Keyword Arguments

* 4.7.3.2. Positional-Only Parameters
• 4.7.3.2. Positional-Only Parameters

* 4.7.3.3. Keyword-Only Arguments
• 4.7.3.3. Keyword-Only Arguments

* 4.7.3.4. Function Examples
• 4.7.3.4. Function Examples

* 4.7.3.5. Recap
• 4.7.3.5. Recap

* 4.7.4. Arbitrary Argument Lists
• 4.7.4. 任意的参数列表

* 4.7.5. Unpacking Argument Lists
• 4.7.5. 解包参数列表

* 4.7.6. Lambda Expressions
• 4.7.6. Lambda 表达式

* 4.7.7. Documentation Strings
• 4.7.7. 文档字符串

* 4.7.8. Function Annotations
• 4.7.8. 函数标注

* 4.8. Intermezzo: Coding Style
• 4.8. 小插曲:编码风格

• 5. Data Structures
• 5. 数据结构

* 5.1. More on Lists
• 5.1. 列表的更多特性

* 5.1.1. Using Lists as Stacks
• 5.1.1. 列表作为栈使用

* 5.1.2. Using Lists as Queues
• 5.1.2. 列表作为队列使用

* 5.1.3. List Comprehensions
• 5.1.3. 列表推导式

* 5.1.4. Nested List Comprehensions
• 5.1.4. 嵌套的列表推导式

* 5.2. The "del" statement
• 5.2. "del" 语句

* 5.3. Tuples and Sequences
• 5.3. 元组和序列

* 5.4. Sets
• 5.4. 集合

* 5.5. Dictionaries
• 5.5. 字典

* 5.6. Looping Techniques
• 5.6. 循环的技巧

* 5.7. More on Conditions
• 5.7. 深入条件控制

* 5.8. Comparing Sequences and Other Types
• 5.8. 序列和其它类型的比较

• 6. Modules
• 6. 模块

* 6.1. More on Modules
• 6.1. 有关模块的更多信息

* 6.1.1. Executing modules as scripts
• 6.1.1. 以脚本的方式执行模块

* 6.1.2. The Module Search Path
• 6.1.2. 模块搜索路径

* 6.1.3. "Compiled" Python files
• 6.1.3. “编译过的”Python文件

* 6.2. Standard Modules
• 6.2. 标准模块

* 6.3. The "dir()" Function
• 6.3. "dir()" 函数

* 6.4. Packages
• 6.4. 包

* 6.4.1. Importing * From a Package
• 6.4.1. 从包中导入 *

* 6.4.2. Intra-package References
• 6.4.2. 子包参考

* 6.4.3. Packages in Multiple Directories
• 6.4.3. 多个目录中的包

• 7. Input and Output
• 7. 输入输出

* 7.1. Fancier Output Formatting
• 7.1. 更漂亮的输出格式

* 7.1.1. Formatted String Literals
• 7.1.1. 格式化字符串文字

* 7.1.2. The String format() Method
• 7.1.2. 字符串的 format() 方法

* 7.1.3. Manual String Formatting
• 7.1.3. 手动格式化字符串

* 7.1.4. Old string formatting
• 7.1.4. 旧的字符串格式化方法

* 7.2. Reading and Writing Files
• 7.2. 读写文件

* 7.2.1. Methods of File Objects
• 7.2.1. 文件对象的方法

* 7.2.2. Saving structured data with "json"
• 7.2.2. 使用 "json" 保存结构化数据

• 8. Errors and Exceptions
• 8. 错误和异常

* 8.1. Syntax Errors
• 8.1. 语法错误

* 8.2. Exceptions
• 8.2. 异常

* 8.3. Handling Exceptions
• 8.3. 处理异常

* 8.4. Raising Exceptions
• 8.4. 抛出异常

* 8.5. Exception Chaining
• 8.5. Exception Chaining

* 8.6. User-defined Exceptions
• 8.6. 用户自定义异常

* 8.7. Defining Clean-up Actions
• 8.7. 定义清理操作

* 8.8. Predefined Clean-up Actions
• 8.8. 预定义的清理操作

• 9. Classes
• 9. 类

* 9.1. A Word About Names and Objects
• 9.1. 名称和对象

* 9.2. Python Scopes and Namespaces
• 9.2. Python 作用域和命名空间

* 9.2.1. Scopes and Namespaces Example
• 9.2.1. 作用域和命名空间示例

* 9.3. A First Look at Classes
• 9.3. 初探类

* 9.3.1. Class Definition Syntax
• 9.3.1. 类定义语法

* 9.3.2. Class Objects
• 9.3.2. 类对象

* 9.3.3. Instance Objects
• 9.3.3. 实例对象

* 9.3.4. Method Objects
• 9.3.4. 方法对象

* 9.3.5. Class and Instance Variables
• 9.3.5. 类和实例变量

* 9.4. Random Remarks
• 9.4. 补充说明

* 9.5. Inheritance
• 9.5. 继承

* 9.5.1. Multiple Inheritance
• 9.5.1. 多重继承

* 9.6. Private Variables
• 9.6. 私有变量

* 9.7. Odds and Ends
• 9.7. 杂项说明

* 9.8. Iterators
• 9.8. 迭代器

* 9.9. Generators
• 9.9. 生成器

* 9.10. Generator Expressions
• 9.10. 生成器表达式

• 10. Brief Tour of the Standard Library
• 10. 标准库简介

* 10.1. Operating System Interface
• 10.1. 操作系统接口

* 10.2. File Wildcards
• 10.2. 文件通配符

* 10.3. Command Line Arguments
• 10.3. 命令行参数

* 10.4. Error Output Redirection and Program Termination
• 10.4. 错误输出重定向和程序终止

* 10.5. String Pattern Matching
• 10.5. 字符串模式匹配

* 10.6. Mathematics
• 10.6. 数学

* 10.7. Internet Access
• 10.7. 互联网访问

* 10.8. Dates and Times
• 10.8. 日期和时间

* 10.9. Data Compression
• 10.9. 数据压缩

* 10.10. Performance Measurement
• 10.10. 性能测量

* 10.11. Quality Control
• 10.11. 质量控制

* 10.12. Batteries Included
• 10.12. 自带电池

• 11. Brief Tour of the Standard Library --- Part II
• 11. 标准库简介 —— 第二部分

* 11.1. Output Formatting
• 11.1. 格式化输出

* 11.2. Templating
• 11.2. 模板

* 11.3. Working with Binary Data Record Layouts
• 11.3. 使用二进制数据记录格式

* 11.4. Multi-threading
• 11.4. 多线程

* 11.5. Logging
• 11.5. 日志

* 11.6. Weak References
• 11.6. 弱引用

* 11.7. Tools for Working with Lists
• 11.7. 用于操作列表的工具

* 11.8. Decimal Floating Point Arithmetic
• 11.8. 十进制浮点运算

• 12. Virtual Environments and Packages
• 12. 虚拟环境和包

* 12.1. Introduction
• 12.1. 概述

* 12.2. Creating Virtual Environments
• 12.2. 创建虚拟环境

* 12.3. Managing Packages with pip
• 12.3. 使用pip管理包

• 13. What Now?
• 13. 接下来?

• 14. Interactive Input Editing and History Substitution
• 14. 交互式编辑和编辑历史

* 14.1. Tab Completion and History Editing
• 14.1. Tab 补全和编辑历史

* 14.2. Alternatives to the Interactive Interpreter
• 14.2. 默认交互式解释器的替代品

• 15. Floating Point Arithmetic: Issues and Limitations
• 15. 浮点算术:争议和限制

* 15.1. Representation Error
• 15.1. 表示性错误

• 16. Appendix
• 16. 附录

* 16.1. Interactive Mode
• 16.1. 交互模式

* 16.1.1. Error Handling
• 16.1.1. 错误处理

* 16.1.2. Executable Python Scripts
• 16.1.2. 可执行的Python脚本

* 16.1.3. The Interactive Startup File
• 16.1.3. 交互式启动文件

* 16.1.4. The Customization Modules
• 16.1.4. 定制模块

results matching ""

    No results matching ""