1
1
<p align =" center " ><img src =" images/logo.png " alt =" " ></p >
2
2
<h1 align =" center " >What the f*ck Python! 🐍</h1 >
3
3
<p align =" center " >An interesting collection of surprising snippets and lesser-known Python features.</p >
4
- [ ![ WTFPL 2.0] [ license-image ]] [ license-url ]
5
4
6
5
Translations: [ Chinese 中文] ( https://github.com/leisurelicht/wtfpython-cn )
7
6
@@ -23,75 +22,75 @@ So, here we go...
23
22
<!-- toc -->
24
23
25
24
- [ Structure of the Examples] ( #structure-of-the-examples )
26
- + [ ▶ Some fancy Title] ( #%E2%96%B6 -some-fancy-title )
25
+ + [ ▶ Some fancy Title] ( #-some-fancy-title )
27
26
- [ Usage] ( #usage )
28
27
- [ 👀 Examples] ( #%F0%9F%91%80-examples )
29
28
* [ Section: Strain your brain!] ( #section-strain-your-brain )
30
- + [ ▶ First things first!] ( #%E2%96%B6 -first-things-first )
31
- + [ ▶ Strings can be tricky sometimes] ( #%E2%96%B6 -strings-can-be-tricky-sometimes )
32
- + [ ▶ Splitsies] ( #%E2%96%B6 -splitsies )
33
- + [ ▶ Hash brownies] ( #%E2%96%B6 -hash-brownies )
34
- + [ ▶ Disorder within order] ( #%E2%96%B6 -disorder-within-order )
35
- + [ ▶ Keep trying...] ( #%E2%96%B6 -keep-trying )
36
- + [ ▶ Deep down, we're all the same.] ( #%E2%96%B6 -deep-down-were-all-the-same )
37
- + [ ▶ For what?] ( #%E2%96%B6 -for-what )
38
- + [ ▶ Evaluation time discrepancy] ( #%E2%96%B6 -evaluation-time-discrepancy )
39
- + [ ▶ How not to use ` is ` operator] ( #%E2%96%B6 -how-not-to-use-is-operator )
40
- + [ ▶ A tic-tac-toe where X wins in the first attempt!] ( #%E2%96%B6 -a-tic-tac-toe-where-x-wins-in-the-first-attempt )
41
- + [ ▶ The sticky output function] ( #%E2%96%B6 -the-sticky-output-function )
42
- + [ ▶ The chicken-egg problem] ( #%E2%96%B6 -the-chicken-egg-problem )
43
- + [ ▶ ` is not ... ` is not ` is (not ...) ` ] ( #%E2%96%B6 -is-not--is-not-is-not- )
44
- + [ ▶ The surprising comma] ( #%E2%96%B6 -the-surprising-comma )
45
- + [ ▶ Strings and the backslashes] ( #%E2%96%B6 -strings-and-the-backslashes )
46
- + [ ▶ not knot!] ( #%E2%96%B6 -not-knot )
47
- + [ ▶ Half triple-quoted strings] ( #%E2%96%B6 -half-triple-quoted-strings )
48
- + [ ▶ Midnight time doesn't exist?] ( #%E2%96%B6 -midnight-time-doesnt-exist )
49
- + [ ▶ What's wrong with booleans?] ( #%E2%96%B6 -whats-wrong-with-booleans )
50
- + [ ▶ Class attributes and instance attributes] ( #%E2%96%B6 -class-attributes-and-instance-attributes )
51
- + [ ▶ Non-reflexive class method] ( #%E2%96%B6 -non-reflexive-class-method )
52
- + [ ▶ yielding None] ( #%E2%96%B6 -yielding-none )
53
- + [ ▶ Nan-reflexivity] ( #%E2%96%B6 -nan-reflexivity )
54
- + [ ▶ Mutating the immutable!] ( #%E2%96%B6 -mutating-the-immutable )
55
- + [ ▶ The disappearing variable from outer scope] ( #%E2%96%B6 -the-disappearing-variable-from-outer-scope )
56
- + [ ▶ Yielding from... return!] ( #%E2%96%B6 -yielding-from-return )
57
- + [ ▶ Lossy zip of iterators] ( #%E2%96%B6 -lossy-zip-of-iterators )
58
- + [ ▶ Subclass relationships] ( #%E2%96%B6 -subclass-relationships )
59
- + [ ▶ The mysterious key type conversion] ( #%E2%96%B6 -the-mysterious-key-type-conversion )
60
- + [ ▶ Let's see if you can guess this?] ( #%E2%96%B6 -lets-see-if-you-can-guess-this )
29
+ + [ ▶ First things first!] ( #-first-things-first )
30
+ + [ ▶ Strings can be tricky sometimes] ( #-strings-can-be-tricky-sometimes )
31
+ + [ ▶ Splitsies] ( #-splitsies )
32
+ + [ ▶ Hash brownies] ( #-hash-brownies )
33
+ + [ ▶ Disorder within order] ( #-disorder-within-order )
34
+ + [ ▶ Keep trying...] ( #-keep-trying )
35
+ + [ ▶ Deep down, we're all the same.] ( #-deep-down-were-all-the-same )
36
+ + [ ▶ For what?] ( #-for-what )
37
+ + [ ▶ Evaluation time discrepancy] ( #-evaluation-time-discrepancy )
38
+ + [ ▶ How not to use ` is ` operator] ( #-how-not-to-use-is-operator )
39
+ + [ ▶ A tic-tac-toe where X wins in the first attempt!] ( #-a-tic-tac-toe-where-x-wins-in-the-first-attempt )
40
+ + [ ▶ The sticky output function] ( #-the-sticky-output-function )
41
+ + [ ▶ The chicken-egg problem] ( #-the-chicken-egg-problem )
42
+ + [ ▶ ` is not ... ` is not ` is (not ...) ` ] ( #-is-not--is-not-is-not- )
43
+ + [ ▶ The surprising comma] ( #-the-surprising-comma )
44
+ + [ ▶ Strings and the backslashes] ( #-strings-and-the-backslashes )
45
+ + [ ▶ not knot!] ( #-not-knot )
46
+ + [ ▶ Half triple-quoted strings] ( #-half-triple-quoted-strings )
47
+ + [ ▶ Midnight time doesn't exist?] ( #-midnight-time-doesnt-exist )
48
+ + [ ▶ What's wrong with booleans?] ( #-whats-wrong-with-booleans )
49
+ + [ ▶ Class attributes and instance attributes] ( #-class-attributes-and-instance-attributes )
50
+ + [ ▶ Non-reflexive class method] ( #-non-reflexive-class-method )
51
+ + [ ▶ yielding None] ( #-yielding-none )
52
+ + [ ▶ Nan-reflexivity] ( #-nan-reflexivity )
53
+ + [ ▶ Mutating the immutable!] ( #-mutating-the-immutable )
54
+ + [ ▶ The disappearing variable from outer scope] ( #-the-disappearing-variable-from-outer-scope )
55
+ + [ ▶ Yielding from... return!] ( #-yielding-from-return )
56
+ + [ ▶ Lossy zip of iterators] ( #-lossy-zip-of-iterators )
57
+ + [ ▶ Subclass relationships] ( #-subclass-relationships )
58
+ + [ ▶ The mysterious key type conversion] ( #-the-mysterious-key-type-conversion )
59
+ + [ ▶ Let's see if you can guess this?] ( #-lets-see-if-you-can-guess-this )
61
60
* [ Section: Appearances are deceptive!] ( #section-appearances-are-deceptive )
62
- + [ ▶ Skipping lines?] ( #%E2%96%B6 -skipping-lines )
63
- + [ ▶ Teleportation] ( #%E2%96%B6 -teleportation )
64
- + [ ▶ Well, something is fishy...] ( #%E2%96%B6 -well-something-is-fishy )
61
+ + [ ▶ Skipping lines?] ( #-skipping-lines )
62
+ + [ ▶ Teleportation] ( #-teleportation )
63
+ + [ ▶ Well, something is fishy...] ( #-well-something-is-fishy )
65
64
* [ Section: Slippery Slopes] ( #section-slippery-slopes )
66
- + [ ▶ Modifying a dictionary while iterating over it] ( #%E2%96%B6 -modifying-a-dictionary-while-iterating-over-it )
67
- + [ ▶ Stubborn ` del ` operation] ( #%E2%96%B6 -stubborn-del-operation )
68
- + [ ▶ Deleting a list item while iterating] ( #%E2%96%B6 -deleting-a-list-item-while-iterating )
69
- + [ ▶ Loop variables leaking out!] ( #%E2%96%B6 -loop-variables-leaking-out )
70
- + [ ▶ Beware of default mutable arguments!] ( #%E2%96%B6 -beware-of-default-mutable-arguments )
71
- + [ ▶ Catching the Exceptions] ( #%E2%96%B6 -catching-the-exceptions )
72
- + [ ▶ Same operands, different story!] ( #%E2%96%B6 -same-operands-different-story )
73
- + [ ▶ The out of scope variable] ( #%E2%96%B6 -the-out-of-scope-variable )
74
- + [ ▶ Be careful with chained operations] ( #%E2%96%B6 -be-careful-with-chained-operations )
75
- + [ ▶ Name resolution ignoring class scope] ( #%E2%96%B6 -name-resolution-ignoring-class-scope )
76
- + [ ▶ Needles in a Haystack] ( #%E2%96%B6 -needles-in-a-haystack )
77
- + [ ▶ Wild imports] ( #%E2%96%B6 -wild-imports )
65
+ + [ ▶ Modifying a dictionary while iterating over it] ( #-modifying-a-dictionary-while-iterating-over-it )
66
+ + [ ▶ Stubborn ` del ` operation] ( #-stubborn-del-operation )
67
+ + [ ▶ Deleting a list item while iterating] ( #-deleting-a-list-item-while-iterating )
68
+ + [ ▶ Loop variables leaking out!] ( #-loop-variables-leaking-out )
69
+ + [ ▶ Beware of default mutable arguments!] ( #-beware-of-default-mutable-arguments )
70
+ + [ ▶ Catching the Exceptions] ( #-catching-the-exceptions )
71
+ + [ ▶ Same operands, different story!] ( #-same-operands-different-story )
72
+ + [ ▶ The out of scope variable] ( #-the-out-of-scope-variable )
73
+ + [ ▶ Be careful with chained operations] ( #-be-careful-with-chained-operations )
74
+ + [ ▶ Name resolution ignoring class scope] ( #-name-resolution-ignoring-class-scope )
75
+ + [ ▶ Needles in a Haystack] ( #-needles-in-a-haystack )
76
+ + [ ▶ Wild imports] ( #-wild-imports )
78
77
* [ Section: Read the docs] ( #section-read-the-docs )
79
- + [ ▶ All sorted?] ( #%E2%96%B6 -all-sorted )
80
- + [ ▶ All-true-ation] ( #%E2%96%B6 -all-true-ation )
78
+ + [ ▶ All sorted?] ( #-all-sorted )
79
+ + [ ▶ All-true-ation] ( #-all-true-ation )
81
80
* [ Section: The Hidden treasures!] ( #section-the-hidden-treasures )
82
- + [ ▶ Okay Python, Can you make me fly?] ( #%E2%96%B6 -okay-python-can-you-make-me-fly )
83
- + [ ▶ ` goto ` , but why?] ( #%E2%96%B6 -goto-but-why )
84
- + [ ▶ Brace yourself!] ( #%E2%96%B6 -brace-yourself )
85
- + [ ▶ Let's meet Friendly Language Uncle For Life] ( #%E2%96%B6 -lets-meet-friendly-language-uncle-for-life )
86
- + [ ▶ Even Python understands that love is complicated] ( #%E2%96%B6 -even-python-understands-that-love-is-complicated )
87
- + [ ▶ Yes, it exists!] ( #%E2%96%B6 -yes-it-exists )
88
- + [ ▶ Ellipsis] ( #%E2%96%B6 -ellipsis )
89
- + [ ▶ Inpinity] ( #%E2%96%B6 -inpinity )
90
- + [ ▶ Let's mangle] ( #%E2%96%B6 -lets-mangle )
81
+ + [ ▶ Okay Python, Can you make me fly?] ( #-okay-python-can-you-make-me-fly )
82
+ + [ ▶ ` goto ` , but why?] ( #-goto-but-why )
83
+ + [ ▶ Brace yourself!] ( #-brace-yourself )
84
+ + [ ▶ Let's meet Friendly Language Uncle For Life] ( #-lets-meet-friendly-language-uncle-for-life )
85
+ + [ ▶ Even Python understands that love is complicated] ( #-even-python-understands-that-love-is-complicated )
86
+ + [ ▶ Yes, it exists!] ( #-yes-it-exists )
87
+ + [ ▶ Ellipsis] ( #-ellipsis )
88
+ + [ ▶ Inpinity] ( #-inpinity )
89
+ + [ ▶ Let's mangle] ( #-lets-mangle )
91
90
* [ Section: Miscellaneous] ( #section-miscellaneous )
92
- + [ ▶ ` += ` is faster] ( #%E2%96%B6 --is-faster )
93
- + [ ▶ Let's make a giant string!] ( #%E2%96%B6 -lets-make-a-giant-string )
94
- + [ ▶ Minor Ones] ( #%E2%96%B6 -minor-ones )
91
+ + [ ▶ ` += ` is faster] ( #--is-faster )
92
+ + [ ▶ Let's make a giant string!] ( #-lets-make-a-giant-string )
93
+ + [ ▶ Minor Ones] ( #-minor-ones )
95
94
* [ ~~~ That's all folks! ~~~] ( #-thats-all-folks- )
96
95
- [ Contributing] ( #contributing )
97
96
- [ Acknowledgements] ( #acknowledgements )
@@ -3479,7 +3478,7 @@ The idea and design for this collection were initially inspired by Denys Dovhan'
3479
3478
3480
3479
# 🎓 License
3481
3480
3482
- [![CC 4 .0][license-image]][license-url]
3481
+ [![WTFPL 2 .0][license-image]][license-url]
3483
3482
3484
3483
© [Satwik Kansal](https://satwikkansal.xyz)
3485
3484
0 commit comments