Python之禅,你知道吗
当调用这行语句时,会有一个有趣的效果.>>>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程序所需要的一些重要原则.
由于百度翻译出来的有些奇怪,这里就我的经验翻译了,可能有错误.
美丽胜于丑陋
明了胜于深奥
简洁胜于复杂
复杂胜于凌乱
扁平胜于嵌套
间隔胜于紧凑
可读性非常重要
即使假借特例的实用的名字,也不要违背以上规则
除非你有需要,任何错误都应该有应对
当存在许多可能,不要去猜测
只要你不是Guido(Python创始人),对于问题尽量找一种,最好是唯一的,明显的方法
做可能好于什么都不做,但不假思索就动手还不如不做
如果你无法向人描述你的方法,那肯定不是一个好方法
如果实现方法容易描述,解释,那可能是个好方法
命名空间是绝妙的理念,要多多运用.