Skip to content

Commit 33b38f1

Browse files
committed
More examples and easter eggs.
Damn, this is going to be awesome!!!
1 parent e2e8e42 commit 33b38f1

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

README.md

+69
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,75 @@ SyntaxError: EOL while scanning string literal
430430
431431
---
432432
433+
### Brace yourself!
434+
435+
If you are one of the people who don't like using whitespace in Python to denote scopes, you can use the C-style {} by importing,
436+
437+
```py
438+
from __future__ import braces
439+
```
440+
441+
**Output:**
442+
```py
443+
File "some_file.py", line 1
444+
from __future__ import braces
445+
SyntaxError: not a chance
446+
```
447+
448+
Braces? No way! You better use Javascript instead.
449+
450+
#### 💡 Explanation:
451+
+ The `__future__` module is normally used to provide features from future versions of Python. The "future" here is however ironic.
452+
+ This is an easter egg concerned with the community's feelings on this issue.
453+
454+
---
455+
456+
### Okay Python, Can you alter gravity?
457+
458+
Well, here you go
459+
460+
```py
461+
import antigravity
462+
```
463+
464+
**Output:**
465+
Sshh.. It's a super secret.
466+
467+
#### 💡 Explanation:
468+
+ `antigravity` module is another easter egg like `from __future__ import braces`, with a difference that it actually works.
469+
+ `import antigravity` opens up a web browser pointing to the [classic XKCD comic](http://xkcd.com/353/) about Python.
470+
+ Well, there's more to it. There's **another easter egg inside the easter egg**. If look at the [code](https://github.com/python/cpython/blob/master/Lib/antigravity.py#L7-L17), there's a function defined that purports to implement the [XKCD's geohashing algorithm](https://xkcd.com/426/).
471+
472+
---
473+
474+
### `goto`, but why?
475+
476+
```py
477+
from goto import goto, label
478+
for i in range(9):
479+
for j in range(9):
480+
for k in range(9):
481+
print("I'm trapped, please rescue!")
482+
if k == 2:
483+
goto .breakout # breaking out from a deeply nested loop
484+
label .breakout
485+
print("Freedom!")
486+
```
487+
488+
**Output (Python 2.3):**
489+
```py
490+
I'm trapped, please rescue!
491+
I'm trapped, please rescue!
492+
Freedom!
493+
```
494+
495+
#### 💡 Explanation:
496+
- A working version of `goto` in Python was [announced](https://mail.python.org/pipermail/python-announce-list/2004-April/002982.html) as an April Fool's joke on 1st April 2004.
497+
- Current versions of Python do not have this module.
498+
- Although it works, but please don't use it. Here's the [reason](https://docs.python.org/3/faq/design.html#why-is-there-no-goto) to why `goto` is not present in Python.
499+
500+
---
501+
433502
### Strings can be tricky sometimes
434503
435504
1\.

0 commit comments

Comments
 (0)