Python宪章

时间:2023-04-29 09:49:46 类型:python
字号:    

简洁(但不需要借助于复杂的技巧)的代码显然更加容易阅读和理解,从而大大加快了开发的速度。的确,在这个信息过载的时代,简洁越来越显示出强大的力量

删繁就简三秋树,标新立异二月花。繁琐、夸张的巴洛克艺术,无论其多么精致、多么吸引眼球,都无法在这个高度内卷的年代逃脱批判。

我们需要那些能够成为我们直觉的工具、符号和思想,以便让我们能够快速响应这日益复杂的世界

简单即是美。

语言的简洁、优美在Python中的地位是如此重要,以至于它被写进了Python“宪章”——PEP20

import this

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!
名字空间是个绝妙的主意,请好好使用!


<