🤵♂️ 个人主页: @计算机魔术师
👨💻 作者简介:CSDN内容合伙人,全栈领域优质创作者。
<font size="3" color="#ad" face="华文琥珀" >Python社区的理念 ————“Zen of Python"
想要获悉这一指导原则,只要在Python解释器中执行命令<font size="3" color="#934" face="微软雅黑" >import this</font>
>>> 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.
......
The Zen of Python, by Tim Peters
<font size="4" color="#ad" face="楷体" > python之禅,Tim Peters著<font>
Beautiful is better than ugly.
<font size="4" color="#ad" face="楷体" > 优雅胜于丑陋,在编写代码中,我们应该尽可能让代码看起来整齐优美,代码之间的缩进,让他人再读代码时能够惊呼“哇,代码编写的是真的优美”,程序员只与“雅“靠边<font>
Explicit is better than implicit.
<font size="4" color="#ad" face="楷体" >显胜于隐,写代码时在编写注释时更应该直戳要点,便于快速理解代码<font>
Simple is better than complex.
<font size="4" color="#ad" face="楷体" >简单胜过复杂,在编写代码,尽量使用明晰易懂的算法,我曾看过有人说最短的代码实现俄罗斯方块,那我猜他的代码一定不会清晰易懂<font>
Complex is better than complicated.
<font size="4" color="#ad" face="楷体" >复杂比难以理解好,不同情况,代码算法最优可能都非常复杂,但是不要选择晦涩难懂的,不然下次看到自己的代码还以为是别人写的啦<font>
Flat is better than nested.
<font size="4" color="#ad" face="楷体" >单一胜于嵌套,在写代码时尽量减小嵌套应用,如各种函数嵌套,想要的函数和你捉迷藏,下次想用可就找不到了<font>
Sparse is better than dense.
<font size="4" color="#ad" face="楷体" >稀疏优于紧密,在看到一坨一坨的代码往往没有欲望,这时编写代码缩进有秩,行与行错落有致,更便于程序的理解<font>
Readability counts.
<font size="4" color="#ad" face="楷体" >可读性很重要<font>
Special cases aren't special enough to break the rules.
<font size="4" color="#ad" face="楷体" >特殊情况不足以破坏规则,即不能违反语法规则
<font>
Although practicality beats purity.
<font size="4" color="#ad" face="楷体" >实践胜于理论,如果你想知道学好编程,有什么秘诀,那么实践就是最好的秘诀<font>
Errors should never pass silently.
<font size="4" color="#ad" face="楷体" >错误不应该被无声的忽略,遇到错误应该及时改正<font>
Unless explicitly silenced.
<font size="4" color="#ad" face="楷体" >除非是无关紧要的警示<font>
In the face of ambiguity, refuse the temptation to guess.
<font size="4" color="#ad" face="楷体" >面对模棱两可,拒绝猜测的诱惑。<font>
There should be one-- and preferably only one --obvious way to do it.
<font size="4" color="#ad" face="楷体" >应该有一种——最好只有一种——明显的方法来实现它,即最优算法<font>
Although that way may not be obvious at first unless you're Dutch.
<font size="4" color="#ad" face="楷体" >除非你是荷兰人,否则这种方式一开始可能并不明显(这里指的是Python之父Guido)<font>
Now is better than never.
<font size="4" color="#ad" face="楷体" >现在开始做比不做好,所以如果想学编程却还在犹豫,请开动吧!<font>
Although never is often better than right now.
<font size="4" color="#ad" face="楷体" >不做比盲目去做好,极限编程的关键原则YAGNI 是You Ain't Gonna Need It(你不会需要它)。即不要不要做过度设计<font>
If the implementation is hard to explain, it's a bad idea.
<font size="4" color="#ad" face="楷体" >如果实现很难解释,那就不是个好主意,在开始解题时,应该优先选择易解释的方法<font>
If the implementation is easy to explain, it may be a good idea.
<font size="4" color="#ad" face="楷体" >如果实现容易解释,那么它可能是一个好主意。<font>
Namespaces are one honking great idea -- let's do more of those!
<font size="4" color="#ad" face="楷体" >命名空间是一个非常棒的想法——让我们更多地使用命名空间!(避免多人开发导致变量名重名情况,人手设置一个)<font>
<font size="2" color="#97" face="华文琥珀" >进程已结束,退出代码0,你现在是否学会了优秀代码的秘诀了呢?
<font>
我正在参与2023腾讯技术创作特训营第二期有奖征文,瓜分万元奖池和键盘手表
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。