The Python TutorialPython教程¶
Python is an easy to learn, powerful programming language. Python是一种易于学习、功能强大的编程语言。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优雅的语法和动态类型,加上它的解释性质,使它成为大多数平台上许多领域的脚本编写和快速应用程序开发的理想语言。
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. Python解释器和广泛的标准库以源代码或二进制形式免费提供给Python网站上的所有主要平台,https://www.python.org/,并可自由分发。The same site also contains distributions of and pointers to many free third party Python modules, programs and tools, and additional documentation.同一个站点还包含许多免费的第三方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解释器可以很容易地用C或C++(或其他可从C调用的语言)实现的新函数和数据类型进行扩展。Python is also suitable as an extension language for customizable applications.Python也适合作为可定制应用程序的扩展语言。
This tutorial introduces the reader informally to the basic concepts and features of the Python language and system. 本教程非正式地向读者介绍Python语言和系统的基本概念和功能。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解释器有助于亲身体验,但所有示例都是独立的,因此教程也可以离线阅读。
For a description of standard objects and modules, see The Python Standard Library. 有关标准对象和模块的描述,请参阅Python标准库。The Python Language Reference gives a more formal definition of the language. Python语言参考给出了该语言更正式的定义。To write extensions in C or C++, read Extending and Embedding the Python Interpreter and Python/C API Reference Manual. 要用C或C++编写扩展,请阅读扩展和嵌入Python解释器和Python/C API参考手册。There are also several books covering Python in depth.还有几本书深入介绍了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. 相反,它引入了许多Python最值得注意的特性,并将让您对该语言的风格和风格有一个很好的了解。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库模块的更多信息。
The Glossary is also worth going through.词汇表也值得一读。
- 1.
Whetting Your Appetite开胃菜 - 2.
Using the Python Interpreter使用Python解释器 - 3.
An Informal Introduction to PythonPython的非正式介绍 - 4.
More Control Flow Tools更多控制流工具- 4.1.
if
Statements语句 - 4.2.
for
Statements语句 - 4.3.
Therange()
Functionrange()
函数 - 4.4.
break
andcontinue
Statements, andelse
Clauses on Loopsbreak
语句和continue
语句,以及循环上的else
子句 - 4.5.
pass
Statements语句 - 4.6.
match
Statements语句 - 4.7.
Defining Functions定义功能 - 4.8.
More on Defining Functions定义函数详解 - 4.9.
Intermezzo: Coding Style间奏曲:编码风格
- 4.1.
- 5.
Data Structures数据结构 - 6.
Modules模块 - 7.
Input and Output输入和输出 - 8.
Errors and Exceptions错误和异常 - 9.
Classes类 - 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自带电池
- 10.1.
- 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附录