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

Python culture

Many programming languages are at the center of a cultural movement. They have their own communities, values, practices, and philosophy, and Python is no exception. The development of the Python language itself is managed through a series of documents called Python Enhancement Proposals, or PEPs. One of the PEPs, called PEP 8, explains how you should format your code, and we follow its guidelines throughout this book. For example, it is PEP 8 which recommends that we use four spaces for indentation in new Python code.

Another of these PEPs, called PEP 20 is called “The Zen of Python”. It refers to 20 aphorisms describing the guiding principles of Python, only 19 of which have been written down. Conveniently, the Zen of Python is never further away than the nearest Python interpreter, as it can always be accessed from the REPL by typing:

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

Throughout this book we'll be highlighting particular nuggets of wisdom from the Zen of Python in moments of zen to understand how they apply to what we have learned. As we've just introduced Python significant indentation, this is a good time for our first moment of zen:

Figure 1.1: Moment of zen

In time, you'll come to appreciate Python's significant whitespace for the elegance it brings to your code, and the ease with which you can read other's.

主站蜘蛛池模板: 扎鲁特旗| 长治市| 广水市| 沙洋县| 仲巴县| 高邑县| 安新县| 平遥县| 天长市| 东乡县| 老河口市| 年辖:市辖区| 铅山县| 曲阜市| 定远县| 方正县| 龙胜| 正定县| 洛隆县| 溧水县| 武清区| 荔波县| 广元市| 五河县| 彭水| 昭觉县| 荆门市| 前郭尔| 绥阳县| 六安市| 贵港市| 嘉祥县| 浮山县| 梧州市| 蒙阴县| 蒲江县| 文山县| 北票市| 永丰县| 泸定县| 长顺县|