Just when you thought, Python could not be more fun.
>>> 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 love
True
>>> love is True
False
>>> love is False
False
>>> love is not True or False
True
>>> love is not True or False; love is love # FML
True
>>> import antigravity
>>> from __future__ import braces
File "<stdin>", line 1
SyntaxError: 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.
- Easiest hello world program in a language without calling any function
- Each and every line is the philosophy of Python's design and is a supreme holy guide
- Maybe just to show that there always should be a new line at the end of a file!
- Not an easter egg, a joke in the interpreter
- It opens this xkcd comic which demonstrates how easy it is to do stuff with modules
- This is to instantly close down any conversation about introducing curly braces to Python
- Guido van Rossum is a big fan of Monty Python's Flying Circus
- It's a substitution cipher called ROT13
- In many languages there are two ways to do the same thing
--no
andno--
. The message has a hidden example in itself - Support for unicode character set for naming identifiers was added in Python3. Though, it is not explicitly preferred while writing code, it adds flavour to working with scientific formulas
- The original code is here with the xkcd comic referenced, and maybe that's why this is also in the
antigravity
module
Please feel free to create a PR and add more!