2018-11-20. 我眼中的python哲學

序號 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
列表生成式

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 原文 原文下載之后的格式略有點不友好,利用簡述的markdown,編輯一下.版權歸原作者 PEP Index > ...
    大飛哥閱讀 2,622評論 0 0
  • Introduction This document gives coding conventions for t...
    wuutiing閱讀 4,816評論 0 9
  • 文/Bruce.Liu1 1.Python前世今生 1.1.Python歷史 Python的創(chuàng)始人: Guido ...
    BruceLiu1閱讀 12,458評論 3 119
  • 不知從何時起,失了拍照的興致。自己對此全然不介,但父母卻甚覺殘念,經(jīng)常提醒我無論出行是游玩還是開會,總之截取些光影...
    破谷閱讀 481評論 7 2
  • 推開窗不見層云 從前彼此也沒有相顧不言 這里的風聲十里都有過去的氣息 無人陷在原地 靜默的合歡樹蒸騰出粉色的花朵 ...
    古籬閱讀 682評論 3 1

友情鏈接更多精彩內(nèi)容