the python tutorial #python指南

The Python Tutorial

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优美的语法和动态类型,加上易于理解的特性,使得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编写的语言)编程的新函数和数据类型很用以扩展。

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 LibraryThe 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.

对于标准对象和模块的描述,请看The Python Standard Library(python标准库)。The Python Language Reference (python语言参考)给出了一个更正式的本语言的介绍。想使用C或者C++写扩展内容,可以阅读Extending and Embedding the Python Interpreter (扩展和嵌入python解释器)及Python/C API Reference Manual(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模块和程序,并且已经准备好学习更多的在The Python Standard Library(python标准库)中描述的各种python库模块。

The Glossary is also worth going through.

专业术语表也值得认真阅读。

[if !supportLists]· [endif]1. Whetting Your Appetite引起你的兴趣

[if !supportLists]· [endif]2. Using the Python Interpreter使用python解释器

[if !supportLists]o [endif]2.1. Invoking the Interpreter调用解释器

[if !supportLists]§ [endif]2.1.1. Argument Passing参数传递

[if !supportLists]§ [endif]2.1.2. Interactive Mode交互模块

[if !supportLists]o [endif]2.2. The Interpreter and Its Environment解释器和它的环境

[if !supportLists]§ [endif]2.2.1. Source Code Encoding源码编译

[if !supportLists]· [endif]3. An Informal Introduction to Python非正式的介绍python

[if !supportLists]o [endif]3.1. Using Python as a Calculator使用python作为一个计算器

[if !supportLists]§ [endif]3.1.1. Numbers数字

[if !supportLists]§ [endif]3.1.2. Strings字符串

[if !supportLists]§ [endif]3.1.3. Lists列表

[if !supportLists]o [endif]3.2. First Steps Towards Programming编程的第一步

[if !supportLists]· [endif]4. More Control Flow Tools更多的控制流工具

[if !supportLists]o [endif]4.1. if Statements#if声明

[if !supportLists]o [endif]4.2. for Statements#for声明

[if !supportLists]o [endif]4.3. The range() Function#range()函数

[if !supportLists]o [endif]4.4. break and continue Statements, and else Clauses on Loops#break和continue声明,循环中的else语句

[if !supportLists]o [endif]4.5. pass Statements#pass声明

[if !supportLists]o [endif]4.6. Defining Functions定义函数

[if !supportLists]o [endif]4.7. More on Defining Functions定义的函数

[if !supportLists]§ [endif]4.7.1. Default Argument Values 定义参数值

[if !supportLists]§ [endif]4.7.2. Keyword Arguments关键字参数

[if !supportLists]§ [endif]4.7.3. Arbitrary Argument Lists任意参数列表

[if !supportLists]§ [endif]4.7.4. Unpacking Argument Lists未打包参数列表

[if !supportLists]§ [endif]4.7.5. Lambda Expressions#Lambda表达式

[if !supportLists]§ [endif]4.7.6. Documentation Strings文档字符

[if !supportLists]§ [endif]4.7.7. Function Annotations函数注释

[if !supportLists]o [endif]4.8. Intermezzo: Coding Style插曲:编译风格

[if !supportLists]· [endif]5. Data Structures 数据结构

[if !supportLists]o [endif]5.1. More on Lists列表扩展

[if !supportLists]§ [endif]5.1.1. Using Lists as Stacks使用列表作为栈

[if !supportLists]§ [endif]5.1.2. Using Lists as Queues使用列表作为队列

[if !supportLists]§ [endif]5.1.3. List Comprehensions列表的理解

[if !supportLists]§ [endif]5.1.4. Nested List Comprehensions嵌套列表的理解

[if !supportLists]o [endif]5.2. The del statement#del声明

[if !supportLists]o [endif]5.3. Tuples and Sequences元组和序列

[if !supportLists]o [endif]5.4. Sets集合

[if !supportLists]o [endif]5.5. Dictionaries字典

[if !supportLists]o [endif]5.6. Looping Techniques循环技术

[if !supportLists]o [endif]5.7. More on Conditions条件扩展

[if !supportLists]o [endif]5.8. Comparing Sequences and Other Types比较序列和其他类型

[if !supportLists]· [endif]6. Modules模块

[if !supportLists]o [endif]6.1. More on Modules模块扩展

[if !supportLists]§ [endif]6.1.1. Executing modules as scripts 作为脚本执行模块

[if !supportLists]§ [endif]6.1.2. The Module Search Path 模块搜索路径

[if !supportLists]§ [endif]6.1.3. “Compiled” Python files #编译python文件

[if !supportLists]o [endif]6.2. Standard Modules标准模块

[if !supportLists]o [endif]6.3. The dir() Function#dir()函数

[if !supportLists]o [endif]6.4. Packages

[if !supportLists]§ [endif]6.4.1. Importing * From a Package#引入*从一个包(这种python语法,用于模块间的引用)

[if !supportLists]§ [endif]6.4.2. Intra-package References内嵌包的参考文档

[if !supportLists]§ [endif]6.4.3. Packages in Multiple Directories多目录中的包

[if !supportLists]· [endif]7. Input and Output输入输出

[if !supportLists]o [endif]7.1. Fancier Output Formatting受欢迎的输出格式

[if !supportLists]§ [endif]7.1.1. Formatted String Literals格式化字符文字

[if !supportLists]§ [endif]7.1.2. The String format() Method#字符的format()方法

[if !supportLists]§ [endif]7.1.3. Manual String Formatting手动的字符格式化

[if !supportLists]§ [endif]7.1.4. Old string formatting老的字符格式化

[if !supportLists]o [endif]7.2. Reading and Writing Files读和写文件

[if !supportLists]§ [endif]7.2.1. Methods of File Objects文件对应的方法

[if !supportLists]§ [endif]7.2.2. Saving structured data with json使用json保存结构化数据

[if !supportLists]· [endif]8. Errors and Exceptions错误与异常

[if !supportLists]o [endif]8.1. Syntax Errors语法错误

[if !supportLists]o [endif]8.2. Exceptions异常

[if !supportLists]o [endif]8.3. Handling Exceptions异常处理

[if !supportLists]o [endif]8.4. Raising Exceptions挂起异常

[if !supportLists]o [endif]8.5. User-defined Exceptions用户定义的异常

[if !supportLists]o [endif]8.6. Defining Clean-up Actions定义清除(恢复)行为

[if !supportLists]o [endif]8.7. Predefined Clean-up Actions预定义清除(恢复)行为

[if !supportLists]· [endif]9. Classes

[if !supportLists]o [endif]9.1. A Word About Names and Objects一个关于名称和对象的词

[if !supportLists]o [endif]9.2. Python Scopes and Namespacespython领域和命名空间

[if !supportLists]§ [endif]9.2.1. Scopes and Namespaces Example领域和命令空间举例

[if !supportLists]o [endif]9.3. A First Look at Classes初识类

[if !supportLists]§ [endif]9.3.1. Class Definition Syntax类的定义语法

[if !supportLists]§ [endif]9.3.2. Class Objects类对象

[if !supportLists]§ [endif]9.3.3. Instance Objects实例对象

[if !supportLists]§ [endif]9.3.4. Method Objects方法对象

[if !supportLists]§ [endif]9.3.5. Class and Instance Variables类和实例变量

[if !supportLists]o [endif]9.4. Random Remarks随机摘要

[if !supportLists]o [endif]9.5. Inheritance继承

[if !supportLists]§ [endif]9.5.1. Multiple Inheritance多重继承

[if !supportLists]o [endif]9.6. Private Variables私有变量

[if !supportLists]o [endif]9.7. Odds and Ends概率和结束

[if !supportLists]o [endif]9.8. Iterators迭代器

[if !supportLists]o [endif]9.9. Generators生成器

[if !supportLists]o [endif]9.10. Generator Expressions生成器解释

[if !supportLists]· [endif]10. Brief Tour of the Standard Library标准库的简单介绍

[if !supportLists]o [endif]10.1. Operating System Interface操作系统接口

[if !supportLists]o [endif]10.2. File Wildcards文件通配符

[if !supportLists]o [endif]10.3. Command Line Arguments命令行参数

[if !supportLists]o [endif]10.4. Error Output Redirection and Program Termination错误输出重定向和程序终止

[if !supportLists]o [endif]10.5. String Pattern Matching字符模式匹配

[if !supportLists]o [endif]10.6. Mathematics数学运算

[if !supportLists]o [endif]10.7. Internet Access链接互联网

[if !supportLists]o [endif]10.8. Dates and Times数据和时间

[if !supportLists]o [endif]10.9. Data Compression数据压缩

[if !supportLists]o [endif]10.10. Performance Measurement性能测量

[if !supportLists]o [endif]10.11. Quality Control质量控制

[if !supportLists]o [endif]10.12. Batteries Included #包含的Batterries

[if !supportLists]· [endif]11. Brief Tour of the Standard Library — Part II标准库的简介第二部分

[if !supportLists]o [endif]11.1. Output Formatting输出格式

[if !supportLists]o [endif]11.2. Templating模板

[if !supportLists]o [endif]11.3. Working with Binary Data Record Layouts与二进制数据记录层工作

[if !supportLists]o [endif]11.4. Multi-threading多线程

[if !supportLists]o [endif]11.5. Logging日志

[if !supportLists]o [endif]11.6. Weak References弱引用

[if !supportLists]o [endif]11.7. Tools for Working with Lists使用列表的工具

[if !supportLists]o [endif]11.8. Decimal Floating Point Arithmetic十进制浮点运算

[if !supportLists]· [endif]12. Virtual Environments and Packages虚拟环境和包

[if !supportLists]o [endif]12.1. Introduction介绍

[if !supportLists]o [endif]12.2. Creating Virtual Environments创建虚拟环境

[if !supportLists]o [endif]12.3. Managing Packages with pip使用pip管理包

[if !supportLists]· [endif]13. What Now?现状

[if !supportLists]· [endif]14. Interactive Input Editing and History Substitution交互式输入编辑和历史替换

[if !supportLists]o [endif]14.1. Tab Completion and History Editing完成建和历史编辑

[if !supportLists]o [endif]14.2. Alternatives to the Interactive Interpreter交互式解释器的替代物

[if !supportLists]· [endif]15. Floating Point Arithmetic: Issues and Limitations浮点运算:问题与限制

[if !supportLists]o [endif]15.1. Representation Error引用错误

[if !supportLists]· [endif]16. Appendix附录

[if !supportLists]o [endif]16.1. Interactive Mode交互式模块

[if !supportLists]§ [endif]16.1.1. Error Handling错误处理

[if !supportLists]§ [endif]16.1.2. Executable Python Scripts执行python脚本

[if !supportLists]§ [endif]16.1.3. The Interactive Startup File交互式启动文件

[if !supportLists]§ [endif]16.1.4. The Customization Modules定制化模块


0��b|��QoD

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,445评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,889评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,047评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,760评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,745评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,638评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,011评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,669评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,923评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,655评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,740评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,406评论 4 320
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,995评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,961评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,197评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,023评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,483评论 2 342

推荐阅读更多精彩内容