PyTips 0x00 - Python 之禅与 Pythonic

发布时间:2019-06-21 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了PyTips 0x00 - Python 之禅与 Pythonic脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

Python 之禅与 Pythonic

Python 之禅是 Python 语言的设计哲学与所倡导的编程理念,Pythonic 则是指基于 Python 理念编写更加符合 Python 语法习惯(idiomatic 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 之禅,by Tim Peters

优美胜于丑陋

明确胜于隐晦

简单胜于复杂

复杂胜于凌乱

扁平胜于嵌套

稀疏胜于紧凑

可读性至关重要

即便特例,也需服从以上规则

除非刻意追求,错误不应跳过

面对歧义条件,拒绝尝试猜测

解决问题的最优方法应该有且只有一个

尽管这一方法并非显而易见(除非你是Python之父)

动手胜于空想

空想胜于不想

难以解释的实现方案,不是好方案

易于解释的实现方案,才是好方案

命名空间是个绝妙的理念,多多益善!

参考

  1. 《Python之禅》的翻译和解释

  2. What is Pythonic?

脚本宝典总结

以上是脚本宝典为你收集整理的PyTips 0x00 - Python 之禅与 Pythonic全部内容,希望文章能够帮你解决PyTips 0x00 - Python 之禅与 Pythonic所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。