程序员们都熟悉 Hello World 的概念。在大多数情况下,它指的是使用该编程语言编写的最小程序,它会将“Hello World”打印到屏幕。这可能是在学习新的编程语言时首先要做的。
Python 有一个酷酷的隐藏的库,做了一些有点与众不同的事:
>>> import __hello__ Hello World...
April fool
下面的 April fool 玩笑是由 Barry Warsaw 提出的,与他的退休有关。他是一位著名的 Python 开发者,在他宣布正式退休的时候,就诞生了下面这个彩蛋:
>>> from __future__ import barry_as_FLUFL >>> 1 <> 2 True
由 C++ 转换到 Python
'braces'库也是一个具有浓厚程序员风格的玩笑,它在其文档中提到,当在编写 Python 代码时使用这个库可提供使用 C++ 花括号的功能。但当你尝试使用它的时候,你将会看到社区对此的看法:
>>> from __future__
import braces SyntaxError: not a chance
哈哈哈,以为导入 braces 就可以使用花括号来结束代码块?Python 的答案是:没门儿!
经典的 Python 之禅
importthis
运行此命令将显示由 Tim Peters 编写的"Zen Of Python(Python 之禅)"。据传这是 Python 中的『八荣八耻』,每个有追求的 Python 程序员都应该谨记于心。
importthis 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!