官术网_书友最值得收藏!

許多編程語言是文化運動的中心。它們有自己的社區、價值觀、實踐和哲學,Python也不例外。開發者通過Python Enhancement Proposals(以下縮寫為PEP)這一系列文檔對Python語言的開發進行管理。其中一個PEP(名為PEP 8)解釋了如何格式化代碼,我們在本書中也會遵循該指南。例如,我們在新的Python代碼中使用4個空格進行縮進,這也是PEP推薦的方式。

這些PEP文檔中的另外一個文檔PEP 20,被稱為“Python之禪”。它引用了20條描述Python指導原則的格言,其中只有19條被記錄下來。方便的是,Python之禪也內置在Python解釋器中,你可以通過輸入以下命令從REPL中看到它:

>>> 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!

在本書中,我們將在禪之刻(moments of zen)中特別強調Python之禪中的至理名言,以理解它們是如何運用在我們所學的知識中的。正如我們剛剛介紹的Python的縮進語法,這是我們展示禪之刻的好時機。

0103.tif

有時候,你會感激Python的縮進語法,它讓你的代碼變得優雅,也可以讓你輕松讀懂他人的代碼。

主站蜘蛛池模板: 天津市| 泽州县| 光泽县| 嘉义市| 清流县| 青州市| 开平市| 德钦县| 兴安盟| 扬中市| 潍坊市| 晋城| 洮南市| 蕉岭县| 万山特区| 五华县| 吉安市| 合肥市| 蒲城县| 日土县| 平和县| 仙居县| 普定县| 南丰县| 迭部县| 延吉市| 香河县| 叙永县| 东海县| 宝兴县| 南皮县| 罗源县| 通州区| 策勒县| 姜堰市| 黄梅县| 昌平区| 沭阳县| 新干县| 贡觉县| 托克逊县|