PYTHON教程
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的官方网站https://www.python.org/上获取到主流平台上Python的解释器和大量标准库的源码及二进制格式文件,且可以自由的发布。在这个网站上还可以找到许多免费的第三方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.
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
- 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.一个简单介绍
- 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.
ifStatements - 4.1.if语句
- 4.2.
forStatements - 4.2.for语句
- 4.3. The
range()Function - 4.3.range()函数
- 4.4.
breakandcontinueStatements, andelseClauses on Loops - 4.4.在循环中的break和continue语句及else子名
- 4.5.
passStatements - 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. Arbitrary Argument Lists
- 4.7.3.可变参数列表
- 4.7.4. Unpacking Argument Lists
- 4.7.4.获取参数列表
- 4.7.5. Lambda Expressions
- 4.7.5.Lambda表达式
- 4.7.6. Documentation Strings
- 4.7.6.文档字符串
- 4.7.7. Function Annotations
- 4.7.7.函数注释
- 4.8. Intermezzo: Coding Style
- 4.8.小插曲:代码风格
- 4.1.
- 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
delstatement - 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. Old string formatting
- 7.1.1.原有的字符格式
- 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. User-defined Exceptions
- 8.5.用户定义异常
- 8.6. Defining Clean-up Actions
- 8.6.定义清理操作
- 8.7. Predefined Clean-up Actions
- 8.7.预定义清理操作
- 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.标签完成与历史编辑
- 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.自定义模块
浙公网安备 33010602011771号