1. 程式人生 > 其它 >Python之禪(Zen of Python)

Python之禪(Zen of Python)

程式碼:

import this

控制檯截圖:


翻譯

  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.(雖然這種方案並不是顯而易見的,因為你不是那個荷蘭人[^1])
  15. Now is better than never.(現在開始做比不做好)
  16. Although never is often better than *right* now.(不做比盲目去做好[^2])
  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!(名稱空間非常有用,我們應當多加利用)

[1]: 這裡指的是 Python 之父 Guido van Rossumm。
[2]: 極限程式設計中的YAGNI原則


Now is better than never!!兄弟們共勉