ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](appetite.xhtml "1. 课前甜点") | - [上一页](../whatsnew/changelog.xhtml "更新日志") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - $('.inline-search').show(0); | # Python 教程 Python 是一种易于学习又功能强大的编程语言。它提供了高效的高级数据结构,还有简单有效的面向对象编程。Python 优雅的语法和动态类型,以及解释型语言的本质,使它成为多数平台上写脚本和快速开发应用的理想语言。 Python 解释器及丰富的标准库以源码或机器码的形式提供,可以到 Python 官网 <https://www.python.org/> 免费获取适用于各个主要系统平台的版本,并可自由地分发。这个网站还包含许多免费第三方 Python 模块、程序和工具以及附加文档的发布页面或链接。 Python 解释器易于扩展,可以使用 C 或 C++(或者其他可以通过 C 调用的语言)扩展新的功能和数据类型。Python 也可用于可定制化软件中的扩展程序语言。 这个教程非正式地介绍 Python 语言和系统的基本概念和功能。最好在阅读的时候准备一个 Python 解释器进行练习,不过所有的例子都是相互独立的,所以这个教程也可以离线阅读。 有关标准的对象和模块,参阅 [Python 标准库](../library/index.xhtml#library-index)。[Python 语言参考](../reference/index.xhtml#reference-index) 提供了更正式的语言参考。想要编写 C 或者 C++ 扩展可以参考 [扩展和嵌入 Python 解释器](../extending/index.xhtml#extending-index) 和 [Python/C API 参考手册](../c-api/index.xhtml#c-api-index)。也有不少书籍深入讲解Python 。 这个教程并没有完整包含每一个功能,甚至常用功能可能也没有全部涉及。这个教程只介绍 Python 中最值得注意的功能,也会让你体会到这个语言的风格特色。学习完这个教程,你将可以阅读和编写 Python 模块和程序,也可以开始学习更多的 Python 库模块,详见 [Python 标准库](../library/index.xhtml#library-index)。 [术语对照表](../glossary.xhtml#glossary) 也很值得阅读一下。 - [1. 课前甜点](appetite.xhtml) - [2. 使用 Python 解释器](interpreter.xhtml) - [2.1. 调用解释器](interpreter.xhtml#invoking-the-interpreter) - [2.1.1. 传入参数](interpreter.xhtml#argument-passing) - [2.1.2. 交互模式](interpreter.xhtml#interactive-mode) - [2.2. 解释器的运行环境](interpreter.xhtml#the-interpreter-and-its-environment) - [2.2.1. 源文件的字符编码](interpreter.xhtml#source-code-encoding) - [3. Python 的非正式介绍](introduction.xhtml) - [3.1. Python 作为计算器使用](introduction.xhtml#using-python-as-a-calculator) - [3.1.1. 数字](introduction.xhtml#numbers) - [3.1.2. 字符串](introduction.xhtml#strings) - [3.1.3. 列表](introduction.xhtml#lists) - [3.2. 走向编程的第一步](introduction.xhtml#first-steps-towards-programming) - [4. 其他流程控制工具](controlflow.xhtml) - [4.1. `if` 语句](controlflow.xhtml#if-statements) - [4.2. `for` 语句](controlflow.xhtml#for-statements) - [4.3. `range()` 函数](controlflow.xhtml#the-range-function) - [4.4. `break` 和 `continue` 语句,以及循环中的 `else` 子句](controlflow.xhtml#break-and-continue-statements-and-else-clauses-on-loops) - [4.5. `pass` 语句](controlflow.xhtml#pass-statements) - [4.6. 定义函数](controlflow.xhtml#defining-functions) - [4.7. 函数定义的更多形式](controlflow.xhtml#more-on-defining-functions) - [4.7.1. 参数默认值](controlflow.xhtml#default-argument-values) - [4.7.2. 关键字参数](controlflow.xhtml#keyword-arguments) - [4.7.3. 任意的参数列表](controlflow.xhtml#arbitrary-argument-lists) - [4.7.4. 解包参数列表](controlflow.xhtml#unpacking-argument-lists) - [4.7.5. Lambda 表达式](controlflow.xhtml#lambda-expressions) - [4.7.6. 文档字符串](controlflow.xhtml#documentation-strings) - [4.7.7. 函数标注](controlflow.xhtml#function-annotations) - [4.8. 小插曲:编码风格](controlflow.xhtml#intermezzo-coding-style) - [5. 数据结构](datastructures.xhtml) - [5.1. 列表的更多特性](datastructures.xhtml#more-on-lists) - [5.1.1. 列表作为栈使用](datastructures.xhtml#using-lists-as-stacks) - [5.1.2. 列表作为队列使用](datastructures.xhtml#using-lists-as-queues) - [5.1.3. 列表推导式](datastructures.xhtml#list-comprehensions) - [5.1.4. 嵌套的列表推导式](datastructures.xhtml#nested-list-comprehensions) - [5.2. `del` 语句](datastructures.xhtml#the-del-statement) - [5.3. 元组和序列](datastructures.xhtml#tuples-and-sequences) - [5.4. 集合](datastructures.xhtml#sets) - [5.5. 字典](datastructures.xhtml#dictionaries) - [5.6. 循环的技巧](datastructures.xhtml#looping-techniques) - [5.7. 深入条件控制](datastructures.xhtml#more-on-conditions) - [5.8. 序列和其它类型的比较](datastructures.xhtml#comparing-sequences-and-other-types) - [6. 模块](modules.xhtml) - [6.1. 有关模块的更多信息](modules.xhtml#more-on-modules) - [6.1.1. 以脚本的方式执行模块](modules.xhtml#executing-modules-as-scripts) - [6.1.2. 模块搜索路径](modules.xhtml#the-module-search-path) - [6.1.3. “编译过的”Python文件](modules.xhtml#compiled-python-files) - [6.2. 标准模块](modules.xhtml#standard-modules) - [6.3. `dir()` 函数](modules.xhtml#the-dir-function) - [6.4. 包](modules.xhtml#packages) - [6.4.1. 从包中导入 \*](modules.xhtml#importing-from-a-package) - [6.4.2. 子包参考](modules.xhtml#intra-package-references) - [6.4.3. 多个目录中的包](modules.xhtml#packages-in-multiple-directories) - [7. 输入输出](inputoutput.xhtml) - [7.1. 更漂亮的输出格式](inputoutput.xhtml#fancier-output-formatting) - [7.1.1. 格式化字符串文字](inputoutput.xhtml#formatted-string-literals) - [7.1.2. 字符串的 format() 方法](inputoutput.xhtml#the-string-format-method) - [7.1.3. 手动格式化字符串](inputoutput.xhtml#manual-string-formatting) - [7.1.4. 旧的字符串格式化方法](inputoutput.xhtml#old-string-formatting) - [7.2. 读写文件](inputoutput.xhtml#reading-and-writing-files) - [7.2.1. 文件对象的方法](inputoutput.xhtml#methods-of-file-objects) - [7.2.2. 使用 `json` 保存结构化数据](inputoutput.xhtml#saving-structured-data-with-json) - [8. 错误和异常](errors.xhtml) - [8.1. 语法错误](errors.xhtml#syntax-errors) - [8.2. 异常](errors.xhtml#exceptions) - [8.3. 处理异常](errors.xhtml#handling-exceptions) - [8.4. 抛出异常](errors.xhtml#raising-exceptions) - [8.5. 用户自定义异常](errors.xhtml#user-defined-exceptions) - [8.6. 定义清理操作](errors.xhtml#defining-clean-up-actions) - [8.7. 预定义的清理操作](errors.xhtml#predefined-clean-up-actions) - [9. 类](classes.xhtml) - [9.1. 名称和对象](classes.xhtml#a-word-about-names-and-objects) - [9.2. Python 作用域和命名空间](classes.xhtml#python-scopes-and-namespaces) - [9.2.1. 作用域和命名空间示例](classes.xhtml#scopes-and-namespaces-example) - [9.3. 初探类](classes.xhtml#a-first-look-at-classes) - [9.3.1. 类定义语法](classes.xhtml#class-definition-syntax) - [9.3.2. 类对象](classes.xhtml#class-objects) - [9.3.3. 实例对象](classes.xhtml#instance-objects) - [9.3.4. 方法对象](classes.xhtml#method-objects) - [9.3.5. 类和实例变量](classes.xhtml#class-and-instance-variables) - [9.4. 补充说明](classes.xhtml#random-remarks) - [9.5. 继承](classes.xhtml#inheritance) - [9.5.1. 多重继承](classes.xhtml#multiple-inheritance) - [9.6. 私有变量](classes.xhtml#private-variables) - [9.7. 杂项说明](classes.xhtml#odds-and-ends) - [9.8. 迭代器](classes.xhtml#iterators) - [9.9. 生成器](classes.xhtml#generators) - [9.10. 生成器表达式](classes.xhtml#generator-expressions) - [10. 标准库简介](stdlib.xhtml) - [10.1. 操作系统接口](stdlib.xhtml#operating-system-interface) - [10.2. 文件通配符](stdlib.xhtml#file-wildcards) - [10.3. 命令行参数](stdlib.xhtml#command-line-arguments) - [10.4. 错误输出重定向和程序终止](stdlib.xhtml#error-output-redirection-and-program-termination) - [10.5. 字符串模式匹配](stdlib.xhtml#string-pattern-matching) - [10.6. 数学](stdlib.xhtml#mathematics) - [10.7. 互联网访问](stdlib.xhtml#internet-access) - [10.8. 日期和时间](stdlib.xhtml#dates-and-times) - [10.9. 数据压缩](stdlib.xhtml#data-compression) - [10.10. 性能测量](stdlib.xhtml#performance-measurement) - [10.11. 质量控制](stdlib.xhtml#quality-control) - [10.12. 自带电池](stdlib.xhtml#batteries-included) - [11. 标准库简介 —— 第二部分](stdlib2.xhtml) - [11.1. 格式化输出](stdlib2.xhtml#output-formatting) - [11.2. 模板](stdlib2.xhtml#templating) - [11.3. 使用二进制数据记录格式](stdlib2.xhtml#working-with-binary-data-record-layouts) - [11.4. 多线程](stdlib2.xhtml#multi-threading) - [11.5. 日志](stdlib2.xhtml#logging) - [11.6. 弱引用](stdlib2.xhtml#weak-references) - [11.7. 用于操作列表的工具](stdlib2.xhtml#tools-for-working-with-lists) - [11.8. 十进制浮点运算](stdlib2.xhtml#decimal-floating-point-arithmetic) - [12. 虚拟环境和包](venv.xhtml) - [12.1. 概述](venv.xhtml#introduction) - [12.2. 创建虚拟环境](venv.xhtml#creating-virtual-environments) - [12.3. 使用pip管理包](venv.xhtml#managing-packages-with-pip) - [13. 接下来?](whatnow.xhtml) - [14. 交互式编辑和编辑历史](interactive.xhtml) - [14.1. Tab 补全和编辑历史](interactive.xhtml#tab-completion-and-history-editing) - [14.2. 默认交互式解释器的替代品](interactive.xhtml#alternatives-to-the-interactive-interpreter) - [15. 浮点算术:争议和限制](floatingpoint.xhtml) - [15.1. 表示性错误](floatingpoint.xhtml#representation-error) - [16. 附录](appendix.xhtml) - [16.1. 交互模式](appendix.xhtml#interactive-mode) - [16.1.1. 错误处理](appendix.xhtml#error-handling) - [16.1.2. 可执行的Python脚本](appendix.xhtml#executable-python-scripts) - [16.1.3. 交互式启动文件](appendix.xhtml#the-interactive-startup-file) - [16.1.4. 定制模块](appendix.xhtml#the-customization-modules) ### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](appetite.xhtml "1. 课前甜点") | - [上一页](../whatsnew/changelog.xhtml "更新日志") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - $('.inline-search').show(0); | © [版权所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 软件基金会是一个非盈利组织。 [请捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [发现了问题](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 创建。