• Stars
    star
    423
  • Rank 102,544 (Top 3 %)
  • Language
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Curated list of all the easter eggs and hidden jokes in Python

Just when you thought, Python could not be more fun.

1. Hello World1

>>> import __hello__
Hello World!
>>> import __phello__
Hello world!

Hello world for python >= 3.11

>>> import __hello__
>>> __hello__.main()
Hello World!
>>> import __phello__
>>> __phello__.main()
Hello World!

2. The classic2

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

3. The missing line from the classic3

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.

4. A simple life lesson4

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

5. Comics, yeah.5

>>> import antigravity

6. It's not a choice, it defines who we are6

>>> from __future__ import braces
  File "<stdin>", line 1
SyntaxError: not a chance

7. Origins7

The name Python has nothing to do with the type of Snake.

8. The confuscation8

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

9. C/C++ anyone?9

From the Zen again,

There should be one-- and preferably only one --obvious way to do it.

10. Naming identifiers can be unspeakably cool10

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

11. Picking a place for meetup?11

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

12. The FLUFL - Friendly Language Uncle For Life from PEP 401 -- BDFL Retirement12

>>> from __future__ import barry_as_FLUFL
>>> 1 <> 2
True
>>> 1 != 2
  File "<stdin>", line 1
    1 != 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.

13. InPynite?13

>>> 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^5 x pi. Interestingly, hash(float('-inf')) yields -10^5 x pi in python3, whereas -271828 i.e - 10^5 x e in python2.

14. types.CodeType - Not for the faint of heart

If you start digging deep into Python's internals you will get a warning in help output for types.CodeType

>>> import types
>>> help(types.CodeType)
...
Help on class code in module builtins:                                                    
                                                                                          
class code(object)                                                                        
 |  code(argcount, kwonlyargcount, nlocals, stacksize, flags, codestring,                 
 |        constants, names, varnames, filename, name, firstlineno,                        
 |        lnotab[, freevars[, cellvars]])                                                 
 |                                                                                        
 |  Create a code object.  Not for the faint of heart.                                    
 |                                                                                        
 |  Methods defined here:                                                                 
 |                                                                                                                                       
 ...

15. Python 3.9 PEG parser14

__peg_parser__ is a keyword in python 3.9, will throw a syntax error if used

>>> __peg_parser__
  File "<stdin>", line 1
    __peg_parser__
    ^
SyntaxError: You found it!

Add more

Please feel free to create a PR and add more!

Footnotes

  1. Easiest hello world program in a language without calling any function ↩

  2. Each and every line is the philosophy of Python's design and is a supreme holy guide ↩

  3. Maybe just to show that there always should be a new line at the end of a file! ↩

  4. Not an easter egg, a joke in the interpreter ↩

  5. It opens this xkcd comic which demonstrates how easy it is to do stuff with modules ↩

  6. This is to instantly close down any conversation about introducing curly braces to Python ↩

  7. Guido van Rossum is a big fan of Monty Python's Flying Circus ↩

  8. It's a substitution cipher called ROT13 ↩

  9. In many languages there are two ways to do the same thing --no and no--. The message has a hidden example in itself ↩

  10. 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 ↩

  11. The original code is here with the xkcd comic referenced, and maybe that's why this is also in the antigravity module ↩

  12. The PEP 401 is an April Fools' Joke - The PEP's number is 401, i.e. 4/01 or April 1st (April Fools' Day). The PEP states that Guido van Rossum is stepping down. The new title given to him would be pronounced "BDEVIL" (Benevolent Dictator Emeritus Vacationing Indefinitely from the Language) and Guido's successor will be Barry Warsaw, or as he is affectionately known, Uncle Barry. Uncle Barry's official title is "FLUFL" (Friendly Language Uncle For Life). There are in-jokes about the Parrot virtual machine and the "non-existent" Python Secret Underground (possibly a throw-back to "TINC" on USENET). ↩

  13. Source. ↩

  14. See this answer ↩

More Repositories

1

keep

A Meta CLI toolkit : Personal shell command keeper and snippets manager
Python
589
star
2

pep8speaks

A GitHub :octocat: app to automatically review Python code style over Pull Requests
Python
584
star
3

ping-me

A cross platform personalized Ping
Python
192
star
4

gsoc-FAQs

An unofficial Google Summer of Code Frequently Asked Questions
111
star
5

Muriel

An electron app to binge-watch anything, without being bored
JavaScript
56
star
6

Minesweeper

🎲 The Game, as the name suggests
Java
26
star
7

PotterScript

/x/pel/e/r/mus
Python
14
star
8

depends

[Unmaintained] Analyze dependencies of Python libraries
Python
13
star
9

KOSS-Python-classes

Introduction to Programming with Python (and basic Open Source Software Development principles)
Jupyter Notebook
9
star
10

mfdf

A collection of My Favorite Daily Fortunes
Shell
7
star
11

orkohunter

Website and Blog (Himanshu Mishra)
JavaScript
7
star
12

MLinProduction

Making Machine Learning easy in production
Python
6
star
13

nxcpy

A NetworkX addon written in C
C
6
star
14

dctrends

/kgp/gonewild | See also https://github.com/OrkoHunter/dc-audio
Python
5
star
15

source_code_ktj

Reverse engineer the executables | Source Code event | Kshitij
Python
5
star
16

slides

Personal slides for public talks and demos
CSS
4
star
17

notify-on-broken-links

A GitHub app that keeps watching your repository for broken links and creates an issue if one is found
3
star
18

VectorEntry-Keyboard

VectorEntry Text Entry Mechanism | MTP Project
Java
3
star
19

test-pep8speaks

Testing the bot @pep8speaks and the app
Python
2
star
20

VectorEntry

Text Entry mechanism for blind people using handheld devices
Java
2
star
21

unnati

Codefundo++ idea
2
star
22

monitor-urls

A URL monitoring service in node js
JavaScript
2
star
23

dc-audio

Listen to the melody created by your DC network
JavaScript
2
star
24

mokita-frontend

https://github.com/nishnik/mokita-backend
CSS
2
star
25

orc

C
1
star
26

ping-me-tornado

Repository for ping-me server running on tornado
Python
1
star
27

jio-hackathon-backend

Backend for jio hackathon app - farmer's marketplace
Python
1
star
28

pep8speaks.org

Website of PEP 8 Speaks
HTML
1
star
29

ping-me-extension

Chrome extension for ping-me (https://github.com/orkohunter/ping-me)
JavaScript
1
star
30

notebooks

Collection of personal IPython notebooks | Feedback :
Jupyter Notebook
1
star
31

github.monitor

A minimalistic react native app using GitHub API for learning purposes
JavaScript
1
star