鱼C论坛

 找回密码
 立即注册
查看: 5033|回复: 4

[新人报道] 学习python第二天 - 领悟python之禅

[复制链接]
发表于 2021-1-4 22:58:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 井十三 于 2021-1-4 23:00 编辑

  1. >>>import this
  2. >>>[font=Times New Roman]The Zen of Python, by Tim Peters[/font]

  3. Beautiful is better than ugly.
  4. Explicit is better than implicit.
  5. Simple is better than complex.
  6. Complex is better than complicated.
  7. Flat is better than nested.
  8. Sparse is better than dense.
  9. Readability counts.
  10. Special cases aren't special enough to break the rules.
  11. Although practicality beats purity.
  12. Errors should never pass silently.
  13. Unless explicitly silenced.
  14. In the face of ambiguity, refuse the temptation to guess.
  15. There should be one-- and preferably only one --obvious way to do it.
  16. Although that way may not be obvious at first unless you're Dutch.
  17. Now is better than never.
  18. Although never is often better than *right* now.
  19. If the implementation is hard to explain, it's a bad idea.
  20. If the implementation is easy to explain, it may be a good idea.
  21. Namespaces are one honking great idea -- let's do more of those!
复制代码

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-1-5 02:01:12 From FishC Mobile | 显示全部楼层
Python之禅


by Tim Peters

优美胜于丑陋(Python 以编写优美的代码为目标)

明了胜于晦涩(优美的代码应当是明了的,命名规范,风格相似)

简洁胜于复杂(优美的代码应当是简洁的,不要有复杂的内部实现)

复杂胜于凌乱(如果复杂不可避免,那代码间也不能有难懂的关系,要保持接口简洁)

扁平胜于嵌套(优美的代码应当是扁平的,不能有太多的嵌套)

间隔胜于紧凑(优美的代码有适当的间隔,不要奢望一行代码解决问题)

可读性很重要(优美的代码是可读的)

即便假借特例的实用性之名,也不可违背这些规则(这些规则至高无上)

不要包容所有错误,除非你确定需要这样做(精准地捕获异常,不写 except:pass 风格的代码)

当存在多种可能,不要尝试去猜测

而是尽量找一种,最好是唯一一种明显的解决方案(如果不确定,就用穷举法)

虽然这并不容易,因为你不是 Python 之父(这里的 Dutch 是指 Guido )

做也许好过不做,但不假思索就动手还不如不做(动手之前要细思量)

如果你无法向人描述你的方案,那肯定不是一个好方案;反之亦然(方案测评标准)

命名空间是一种绝妙的理念,我们应当多加利用(倡导与号召)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2021-1-5 02:02:21 From FishC Mobile | 显示全部楼层
兄弟顶你( ' ' ),这是甲鱼给的翻译,给你弄上
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-1-5 09:36:36 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-7-24 07:24:10 From FishC Mobile | 显示全部楼层
寓意无穷
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-11 22:22

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表