
PyTips
項(xiàng)目地址:https://git.io/pytips
Python 之禪與 Pythonic
Python 之禪是 Python 語(yǔ)言的設(shè)計(jì)哲學(xué)與所倡導(dǎo)的編程理念,Pythonic 則是指基于 Python 理念編寫(xiě)更加符合 Python 語(yǔ)法習(xí)慣(idiomatic Python)的代碼,這也是本項(xiàng)目所追求的目標(biāo),因此以本篇作為開(kāi)頭。
import this
The Zen of Python, by Tim Peters
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!
Python 之禪,by Tim Peters
優(yōu)美勝于丑陋
明確勝于隱晦
簡(jiǎn)單勝于復(fù)雜
復(fù)雜勝于凌亂
扁平勝于嵌套
稀疏勝于緊湊
可讀性至關(guān)重要
即便特例,也需服從以上規(guī)則
除非刻意追求,錯(cuò)誤不應(yīng)跳過(guò)
面對(duì)歧義條件,拒絕嘗試猜測(cè)
解決問(wèn)題的最優(yōu)方法應(yīng)該有且只有一個(gè)
盡管這一方法并非顯而易見(jiàn)(除非你是Python之父)
動(dòng)手勝于空想
空想勝于不想
難以解釋的實(shí)現(xiàn)方案,不是好方案
易于解釋的實(shí)現(xiàn)方案,才是好方案
命名空間是個(gè)絕妙的理念,多多益善!