| 序號 | import this | 翻譯 |
|---|---|---|
| 0 | The Zen of Python, by Tim Peters | PY之禪 |
| 1 | Beautiful is better than ugly. | 美麗勝丑陋 |
| Explicit is better than implicit. | 直白勝隱晦 | |
| Simple is better than complex. | 簡單勝復雜 | |
| Complex is better than complicated. | 復雜勝繁復 | |
| 5 | Flat is better than nested. | 扁平勝嵌套 |
| Sparse is better than dense. | 稀疏勝稠密 | |
| Readability counts. | 可塑性重要(人也一樣) | |
| Special cases aren't special enough to break the rules. | 特殊負規(guī)則 | |
| Although practicality beats purity. | 雖純粹負實用(追求純粹,注重實用,優(yōu)化特殊) | |
| 10 | 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. | 雖不至,向往之 | |
| 15 | 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! | 好想法,多踐行 |
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創(chuàng)世者荷蘭Guido van Rossum.
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.
美優(yōu)于丑. 追求美是人的天性.
直白優(yōu)于隱晦. 所以有很多人更愿意與計算機打交道.
簡潔優(yōu)于復雜. python是一種簡潔的語言.
復雜優(yōu)于繁復. 代碼要結構清晰.
扁平優(yōu)于嵌套.
間隔優(yōu)于緊湊.
Readability counts.
可讀性很重要. 從面向過程編程進階到使用函數(shù),使用類,面向?qū)ο缶幊?
找到this.py文件查看源碼.
s = """Gur Mra bs Clguba, ol Gvz Crgref
Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
Nygubhtu cenpgvpnyvgl orngf chevgl.
Reebef fubhyq arire cnff fvyragyl.
Hayrff rkcyvpvgyl fvyraprq.
Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.
Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.
Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.
Abj vf orggre guna arire.
Nygubhtu arire vf bsgra orggre guna *evtug* abj.
Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!"""
d = {}
for c in (65, 97):
for i in range(26):
d[chr(i+c)] = chr((i+13) % 26 + c)
print("".join([d.get(c, c) for c in s]))
閱讀代碼,為對稱加密.
效果:將字母錯位.
d = {}
''' 新建d字典'''
for c in (65, 97):
''' chr(65)=A;chr(97)=a '''
for i in range(26):
d[chr(i+c)] = chr((i+13) % 26 + c)
''' d中鍵值錯13位對應'''
print("".join([d.get(c, c) for c in s]))
''' "sep".join()函數(shù):以sep作為分隔符,將seq所有的元素合并成一個新的字符串. 列表生成式. dict.get("查找值","返回值")'''
參考:
Python Philosophy(Python哲學)翻譯及簡析
The Zen of Python, by Tim Peters
列表生成式