Python中的另一个有趣的小彩蛋

Author Avatar
IDforHYIT 10月 02, 2018

本页面访问量

  • 在其它设备中阅读本文章

Python小彩蛋又来啦~

1. 导入this

在Python中导入this后不要做任何操作,运行py代码即可。

import this

代码还是真的就一行~

2. 效果

>>> 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 之父。
做好过不做,但没有思考的做还不如不做
如果实现很难说明,那它是个坏想法。
如果实现容易解释,那它有可能是个好想法。
命名空间是个绝妙的想法,请多加利用

import this 中隐藏了一首《Python之禅》的诗,它是Python中的『八荣八耻』,作者是 Tim Peters ,每个有追求的Python程序员都应该谨记于心。

​ 《The Zen of Python》是核心开发者 Tim Peters 将 Python 它爹的语言设计原则浓缩为20条格言,在 PEP20 中被正式引入Python,不过真正的内容却只有19条,不知这算不算是彩蛋中的彩蛋。

3. 附赠:

​ 其他有趣的小彩蛋:

你知道 Python 这五个有趣的彩蛋吗?

细数10个隐藏在Python中的彩蛋

This blog is under a CC BY-NC-SA 3.0 Unported License
本文链接:https://idforhyit.github.io/2018/10/02/Python中的另一个小彩蛋/