Python之道 (大道至簡)

來源:互聯網
上載者:User

The Zen of Python

1.       Beautiful is better than ugly.

2.       Explicit is better than implicit.

3.       Simple is better than complex.

4.       Complex is better than complicated.

5.       Flat is better than nested.

6.       Sparse is better than dense.

7.       Readability counts.

8.       Special cases aren't special enough to break the rules.

9.       Although practicality beats purity.

10.   Errors should never pass silently.

11.   Unless explicitly silenced.

12.   In the face of ambiguity, refuse the temptation to guess.

13.   There should be one— and preferably only one —obvious way to do it.

14.   Although that way may not be obvious at first unless you're Dutch.

15.   Now is better than never.

16.   Although never is often better than right now.

17.   If the implementation is hard to explain, it's a bad idea.

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

19.   Namespaces are one honking great idea — let's do more of those!

 (a poem by Tim Peters)

 

· 優美勝於醜陋,

· 明了勝於晦澀。

· 簡潔勝於複雜,

· 複雜勝於淩亂。

· 扁平勝於嵌套,

· 稀疏勝於密繁。

· 可讀性很重要!

· 即便假借特例的實用性之名,也不可違背這些規則。

· 不要放過一切錯誤,除非錯誤本身需要以忽略對待。

· 不確定面前,我們應抵擋妄加猜測的引誘。

· 應該有一種,也但願只有這一種是顯而易見的解決之道。

· 萬事開頭難,除非荷蘭人。

· 做好過不做,而不假思索就動手還不如不做。

· 如果某個實現無法很好闡釋,那麼它肯定是一個糟糕的辦法;

· 如果某個實現很容易說清楚,那麼它可能就是個不錯的方案。

· 命名空間是個絕妙的發明 —— 對此我們應多多益善!

 

這些都是摘自網上 , 之所以特意發博 , 是因為用了好幾年 python, 確實深深體會到他的優點 . 並對能寫下這段話的 Tim Peters 表示深深敬意 , 大道至簡 , 不光是用 python, 寫任意程式 , 做任何事何嘗不是這樣 .

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.