序号 | 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. | 特殊负规则 | |
Although practicality beats purity. | 虽纯粹负实用(追求纯粹,注重实用,优化特殊) | |
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创世者荷兰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.
美优于丑. 追求美是人的天性.
直白优于隐晦. 所以有很多人更愿意与计算机打交道.
简洁优于复杂. python是一种简洁的语言.
复杂优于繁复. 代码要结构清晰.
扁平优于嵌套.
间隔优于紧凑.
Readability counts.
可读性很重要. 从面向过程编程进阶到使用函数,使用类,面向对象编程.
找到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()函数:以sep作为分隔符,将seq所有的元素合并成一个新的字符串. 列表生成式. dict.get("查找值","返回值")'''
参考:
Python Philosophy(Python哲学)翻译及简析
The Zen of Python, by Tim Peters
列表生成式