程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

【由淺入深學Python】Python之禅

編輯:Python

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!

命名空間是個超級棒的主意,讓我們多一些這樣的想法。


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved