python之禅

来源:互联网 发布:linux 用户环境变量 编辑:程序博客网 时间:2024/06/05 19:29

一共19条,由Tim Peters总结,在Python命令行里打import this就可以看到这些内容
为了防止在翻译的过程中丢失词意,在括号里注明了更全面一些的原意

Beautiful is better than ugly.
1,美比丑好

Explicit is better than implicit.
2,显式(清晰、明确)比隐式(含蓄、暗示)好

Simple is better than complex.
3,简单比复杂好

Complex is better than complicated.
4,复杂比纠缠好
(complex为常用词,表示由一些互相联系、互相作用的部分组成,需要有相当的研究、知识和经验才能理解、操作或处理。
complicated为正式用词,表示由于组成部分太多、互相关系太复杂而不能马上理解,预期比comlex更重。)

Flat is better than nested.
5,平坦(扁平)比嵌套好

Sparse is better than dense.
6,稀疏比稠密好

Readability counts.
7,可读性很重要

Special cases aren’t special enough to break the rules.
8,特例不应破坏原则

Although practicality beats purity.
9,虽然实用性胜过纯粹性

Errors should never pass silently.
10,错误不应被默默放过

Unless explicitly silenced.
11,除非明确要求默默放过错过

In the face of ambiguity, refuse the temptation to guess.
12,在含糊(不明确)面前,拒绝猜测(推测)

There should be one– and preferably only one –obvious way to do it.
13,应该有一个明显(显而易见)的方案完成任务,而且最好只有一个明显的方案

Although that way may not be obvious at first unless you’re Dutch.
14,虽然起初那个方案也许并不明显,除非你是Python之父

Now is better than never.
15,现在做比永远不做好

Although never is often better than right now.
16,虽然永远不做通常好过马上就做

If the implementation is hard to explain, it’s a bad idea.
17,如果很难解释一个实现,这个实现不是个好方案

If the implementation is easy to explain, it may be a good idea.
18,如果容易解释一个实现,这个实现也许是个好方案

Namespaces are one honking great idea – let’s do more of those!
19,命名空间是非常好的理念,我们应多多使用


原文:http://legacy.python.org/dev/peps/pep-0020/