Python之禅
Python之禅(The Zen of Python)是Python之父Guido van Rossum所著的一篇文章,总结了Python语言的哲学。
文章开头写道:
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!
下面我们逐行分析一下这些名言。
Beautiful is better than ugly.
“美丽胜于丑陋”。这句话的意思是说,我们应该尽量写出美丽的代码,而不是丑陋的代码。
这也是PEP20中所说的“There should be one-- and preferably only one --obvious way to do it”的另一种表达。
Explicit is better than implicit.
“明了胜于晦涩”。这句话的意思是说,我们应该尽量写出明了的代码,而不是晦涩难懂的代码。
这句话的含义与“Readability counts.”是一致的。
Simple is better than complex.
“简单胜于复杂”。这句话的意思是说,我们应该尽量写出简单的代码,而不是复杂的代码。
这句话的含义与“There should be one-- and preferably only one --obvious way to do it”是一致的。
Complex is better than complicated.
“复杂胜于繁琐”。这句话的意思是说,我们应该尽量写出复杂的代码,而不是繁琐的代码。
这句话的含义与“There should be one-- and preferably only one --obvious way to do it”是一致的。
Flat is better than nested.
“扁平胜于嵌套”。这句话的意思是说,我们应该尽量写出扁平的代码,而不是嵌套的代码。
这句话的含义与“There should be one-- and preferably only one --obvious way to do it”是
顺便介绍一下我的另一篇专栏, 《100天精通Python - 快速入门到黑科技》专栏,是由 CSDN 内容合伙人丨全站排名 Top 4 的硬核博主 不吃西红柿 倾力打造。 基础知识篇以理论知识为主,旨在帮助没有语言基础的小伙伴,学习我整理成体系的精华知识,快速入门构建起知识框架;黑科技应用篇以实战为主,包括办公效率小工具、爬虫、数据分析、机器学习、计算机视觉、自然语言处理、数据可视化等等,让你会用一段简单的Python程序,自动化解决工作和生活中的问题,甚至成为红客。
🍅 订阅福利:原价299,限时1折订阅专栏进入千人全栈VIP答疑群,作者优先解答机会(代码指导/学习方法指引),群里大佬可以抱团取暖(大厂/外企内推机会)
🍅 订阅福利:简历指导、招聘内推、80G全栈学习视频、300本IT电子书:Python、Java、前端、大数据、数据库、算法、爬虫、数据分析、机器学习、面试题库等等
🍅 专栏地址: 点击《100天精通Python - 快速入门到黑科技》