Python文學家為Python寫的一首詞?(附中英文版)

Python文學家為Python寫的一首詞?(附中英文版)

The Zen of Python, by Tim Peters

(Python之禪 by Tim Peters)

Beautiful is better than ugly.

(優美勝於醜陋(Python 以編寫優美的代碼為目標))

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 arent special enough to break the rules.

(即便假借特例的實用性之名,也不可違背這些規則(這些規則至高無上))

Although practicality beats purity.

(不要包容所有錯誤,除非你確定需要這樣做(精準地捕獲異常,不寫 except:pass 風格的代碼))

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.

(雖然這並不容易,因為你不是 Python 之父(這裡的 Dutch 是指 Guido ))

Although that way may not be obvious at first unless youre Dutch.

(如果你無法向人描述你的方案,那肯定不是一個好方案;反之亦然(方案測評標準))

Now is better than never.

(現在總比沒有好)

Although never is often better than *right* now.

(做也許好過不做,但不假思索就動手還不如不做(動手之前要細思量))

If the implementation is hard to explain, its a bad idea.

(如果實現很難解釋,這是個壞主意)

If the implementation is easy to explain, it may be a good idea.

(如果你無法向人描述你的方案,那肯定不是一個好方案;反之亦然(方案測評標準))

Namespaces are one honking great idea -- lets do more of those!

(命名空間是一種絕妙的理念,我們應當多加利用(倡導與號召))

推薦閱讀:

小說人物關係的可視化
Python小白篇(一):Visual Studio 2013下Python開發環境搭建
1.5 本章小結
Python 抓取網頁亂碼原因分析
linux如何高效的學習語言編程?

TAG:Python | Python入門 | python爬蟲 |