>>> import __hello__Hello World!
>>> 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!
The Zen of Python was introduced in PEP 20. It is supposed to be 20 aphorisms, but only 19 of which have been written down.
>>> import this...>>> love = this>>> this is loveTrue>>> love is TrueFalse>>> love is FalseFalse>>> love is not True or FalseTrue>>> love is not True or False; love is love # FMLTrue
>>> import antigravity
>>> from __future__ import bracesFile "<stdin>", line 1SyntaxError: not a chance
The name Python has nothing to do with the type of Snake.
This is how the this.py
module looks, which prints the Zen of Python.
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]))
The code for the Zen violates itself. It’s not beautiful but ugly, not explicit but implicit. This would probably be the only module to go against the spirit of what it says itself. .
From the Zen again,
There should be one-- and preferably only one --obvious way to do it.
Just when you thought that working in Python couldn’t possibly be any more fun,
>>> from math import pi>>> π = pi>>> area = π * r**2
>>> résumé = 'knows Python'>>> 'Python' in résuméTrue
>>> from antigravity import geohash>>> # Your location, a date and that date's (or most recent) DJIA opening.>>> geohash(37.421542, -122.085589, b'2005-05-26-10458.68')37.857713 -122.544543
This can generate a GPS coordinate in a region which is 1 longitude long and 1 latitude wide based on your location.
>>> from __future__ import barry_as_FLUFL>>> 1 <> 2True>>> 1 != 2File "<stdin>", line 11 != 2^SyntaxError: invalid syntax
Recognized that the != inequality operator in Python 3.0 was a horrible, finger pain inducing mistake, the FLUFL reinstates the <> diamond operator as the sole spelling.
>>> infinity = float('infinity')>>> hash(infinity)314159>>> hash(float('-inf'))-314159
A hash is a fixed sized integer that identifies a particular value. On a closer look, the hash of infinity is 10⁵ x pi. Interestingly, hash(float(‘-inf’)) yields -10⁵ x pi in python3, whereeas -271828 i.e — 10⁵ x e in python2.
--no
and no--
. The message has a hidden example in itselfantigravity
module