Python 简明教程
Python - Overview
Python 是高级、解释型、交互性和面向对象的脚本语言。Python 的设计具有很高的可读性。它频繁地使用英语关键字,而其他语言则使用标点符号,并且它的句法结构比其他语言少。
Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than other languages.
-
Python is Interpreted − Python is processed at runtime by the interpreter. You do not need to compile your program before executing it. This is similar to PERL and PHP.
-
Python is Interactive − You can actually sit at a Python prompt and interact with the interpreter directly to write your programs.
-
Python is Object-Oriented − Python supports Object-Oriented style or technique of programming that encapsulates code within objects.
-
Python is a Beginner’s Language − Python is a great language for the beginner-level programmers and supports the development of a wide range of applications from simple text processing to WWW browsers to games.
Python 是一种开源跨平台编程语言。它可以在所有主流操作系统平台 Linux、Windows 和 Mac OS 上使用(与 GNU 通用公共许可证兼容)。
Python is an open-source and cross-platform programming language. It is available for use under Python Software Foundation License (compatible to GNU General Public License) on all the major operating system platforms Linux, Windows and Mac OS.
为了促进新功能并保持可读性,开发了 Python 增强提案 (PEP) 流程。这个流程允许任何人提交一个 PEP,用于新的功能、库或其他添加项。
To facilitate new features and to maintain that readability, the Python Enhancement Proposal (PEP) process was developed. This process allows anyone to submit a PEP for a new feature, library, or other addition.
Python 的设计理念强调简单、可读性和明确性。Python 以其包含电池的方法而闻名,因为 Python 软件随附的标准函数和模块库非常全面。
The design philosophy of Python emphasizes on simplicity, readability and unambiguity. Python is known for its batteries included approach as Python software is distributed with a comprehensive standard library of functions and modules.
Python 的设计理念在中得到记录。它包含十九条格言,例如 -
Python’s design philosophy is documented in the Zen of Python. It consists of nineteen aphorisms such as −
-
Beautiful is better than ugly
-
Explicit is better than implicit
-
Simple is better than complex
-
Complex is better than complicated
要获取完整的 Python Zen 文档,请在 Python Shell 中键入 import this −
To obtain the complete Zen of Python document, type import this in the Python Shell −
>>>import this
这将产生以下 19 条格言 -
This will produce following 19 aphorisms -
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
Python 支持命令式、结构化和面向对象编程方法。它还提供函数式编程的功能。
Python supports imperative, structured as well as object-oriented programming methodology. It provides features of functional programming as well.
Pythonic Code Style
Python 让您自由选择以面向对象、过程化、功能性、面向方面,甚至以面向逻辑的方式编程。这些自由使 Python 成为编写干净且优美的代码的出色语言。
Python leaves you free to choose to program in an object-oriented, procedural, functional, aspect-oriented, or even logic-oriented way. These freedoms make Python a great language to write clean and beautiful code.
Python 代码样式实际上更像是一种设计理念,并且建议编写具有以下特征的代码:
Pythonic Code Style is actually more of a design philosophy and suggests to write a code which is :
-
Clean
-
Simple
-
Beautiful
-
Explicit
-
Readable