Python之禅是隐藏在Python语言中的彩蛋,是Tim Peters为了编写更加优美、简洁、易读、可扩展的程序,而倡导的准则。在Python的交互界面输入import this,回车运行,这就是《The Zen Of Python》。
Python之禅体现了Python语言的设计哲学,其中的观点适用于任何的程序设计中。其实这不仅仅是程序设计的哲学,也是一种人生哲学,一名优秀的程序设计者应该有较深的哲学和人文科学积累。
>> import this
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!
翻译: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.
尽管在开始时没有那么显而易见,除非你是个荷兰人。(Python创始人是个荷兰人,或是调侃复杂问题像是看荷兰语)
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!
命名空间是个超级棒的主意,让我们多一些这样的想法。



