- 寫給程序員的Python教程
- (挪)羅伯特·斯莫爾希雷 (美)奧斯汀·賓厄姆
- 507字
- 2020-07-10 16:09:15
1.5 Python文化
許多編程語言是文化運動的中心。它們有自己的社區、價值觀、實踐和哲學,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的縮進語法,這是我們展示禪之刻的好時機。
有時候,你會感激Python的縮進語法,它讓你的代碼變得優雅,也可以讓你輕松讀懂他人的代碼。
推薦閱讀
- HornetQ Messaging Developer’s Guide
- 程序員修煉之道:程序設計入門30講
- Software Testing using Visual Studio 2012
- 華為HMS生態與應用開發實戰
- 深入實踐Spring Boot
- 樂學Web編程:網站制作不神秘
- C語言程序設計
- Learning Python Design Patterns(Second Edition)
- concrete5 Cookbook
- RabbitMQ Essentials
- C#應用程序設計教程
- Python項目實戰從入門到精通
- FFmpeg開發實戰:從零基礎到短視頻上線
- scikit-learn Cookbook(Second Edition)
- Visual C++程序設計與項目實踐