funny_python 00 The Zen of Python

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了funny_python 00 The Zen of Python相关的知识,希望对你有一定的参考价值。

# 打算每天多动的时候尽量搜索一些和coding相关的funny stuff 

Day 00 - PEP 20 The Zen of Python 

 

在shell里面输入python -m this 回车,可以欣赏到Tim Peters 的The Zen of Python 

除此之外,还可以通过import this 来获取这段文字 

好奇的瓦还试了import that等其他看起来类似的但明显没可能再有好玩儿的事情发生的关键字,果然没有内容。

机智的我找到了this.py的源码(算是一个复活节彩蛋了),代码如下:

 1 s = """Gur Mra bs Clguba, ol Gvz Crgref
 2 
 3 Ornhgvshy vf orggre guna htyl.
 4 Rkcyvpvg vf orggre guna vzcyvpvg.
 5 Fvzcyr vf orggre guna pbzcyrk.
 6 Pbzcyrk vf orggre guna pbzcyvpngrq.
 7 Syng vf orggre guna arfgrq.
 8 Fcnefr vf orggre guna qrafr.
 9 Ernqnovyvgl pbhagf.
10 Fcrpvny pnfrf nera‘g fcrpvny rabhtu gb oernx gur ehyrf.
11 Nygubhtu cenpgvpnyvgl orngf chevgl.
12 Reebef fubhyq arire cnff fvyragyl.
13 Hayrff rkcyvpvgyl fvyraprq.
14 Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.
15 Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.
16 Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh‘er Qhgpu.
17 Abj vf orggre guna arire.
18 Nygubhtu arire vf bsgra orggre guna *evtug* abj.
19 Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg‘f n onq vqrn.
20 Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
21 Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg‘f qb zber bs gubfr!"""
22 
23 d = {}
24 for c in (65, 97):
25     for i in range(26):
26         d[chr(i+c)] = chr((i+13) % 26 + c)
27 
28 print("".join([d.get(c, c) for c in s]))

实际输出结果:

C:\Users\Naomi>python -m 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 arent 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 youre Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, its a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- lets do more of those!

C:\Users\Naomi>

 

搜索的时候还发现了一个python humor列表,还没有深入研究,不过看起来应该很有意思的样子。想什么呢,python (Monty Python‘s Flying Circus) 原本就是非常有意思的啊!

那就请继续探索python humor吧!Animo~! 

 

References: 

PEP 20 -- The Zen of Python 官方文档

https://www.python.org/dev/peps/pep-0020/

维基百科The Zen of Python

https://en.wikipedia.org/wiki/Zen_of_Python

以上是关于funny_python 00 The Zen of Python的主要内容,如果未能解决你的问题,请参考以下文章

The Zen of Python

The zen of python

python之禅 the zen of python

The Zen of Python, by Tim Peters

The Zen of Python( Python之禅)

Python之禅(The Zen of Python)