You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<palign="center">An interesting collection of surprising snippets and lesser-known Python features.</p>
2
+
<h1align="center">What the f*ck Python! 🐍</h1>
3
+
<palign="center">An interesting collection of surprising snippets and lesser-known Python features.</p>
4
4
5
5
[![WTFPL 2.0][license-image]][license-url]
6
6
@@ -77,7 +77,7 @@ So, here we go...
77
77
-[▶ Yes, it exists!](#-yes-it-exists)
78
78
-[▶ Inpinity *](#-inpinity-)
79
79
-[▶ Mangling time! *](#-mangling-time-)
80
-
-[Section: Miscallaneous](#section-miscallaneous)
80
+
-[Section: Miscellaneous](#section-miscellaneous)
81
81
-[▶ `+=` is faster](#--is-faster)
82
82
-[▶ Let's make a giant string!](#-lets-make-a-giant-string)
83
83
-[▶ Explicit typecast of strings](#-explicit-typecast-of-strings)
@@ -97,22 +97,22 @@ All the examples are structured like below:
97
97
98
98
> ### ▶ Some fancy Title *
99
99
> The asterisk at the end of the title indicates the example was not present in the first release and has been recently added.
100
-
>
100
+
>
101
101
> ```py
102
102
># Setting up the code.
103
103
># Preparation for the magic...
104
104
>```
105
-
>
105
+
>
106
106
>**Output (Python version):**
107
107
>```py
108
108
>>>> triggering_statement
109
109
> Probably unexpected output
110
110
>```
111
111
> (Optional): One line describing the unexpected output.
112
-
>
113
-
>
112
+
>
113
+
>
114
114
>#### 💡 Explanation:
115
-
>
115
+
>
116
116
>* Brief explanation of what's happening and why is it happening.
117
117
>```py
118
118
> Setting up examples for clarification (if necessary)
@@ -241,7 +241,7 @@ some_dict[5] = "Python"
241
241
True
242
242
```
243
243
**Note:** Objects with different values may also have same hash (known ashash collision).
244
-
* When the statement `some_dict[5] = "Python"`is executed, the existing value "JavaScript"is overwritten with"Python" because Python recongnizes`5`and`5.0`as the same keys of the dictionary `some_dict`.
244
+
* When the statement `some_dict[5] = "Python"`is executed, the existing value "JavaScript"is overwritten with"Python" because Python recognizes`5`and`5.0`as the same keys of the dictionary `some_dict`.
245
245
* This StackOverflow [answer](https://stackoverflow.com/a/32211042/4354153) explains beautifully the rationale behind it.
246
246
247
247
---
@@ -1135,7 +1135,7 @@ str
1135
1135
and type(other) is SomeClass
1136
1136
and super().__eq__(other)
1137
1137
)
1138
-
1138
+
1139
1139
# When we define a custom __eq__, Python stops automatically inheriting the
1140
1140
# __hash__ method, so we need to define it as well
1141
1141
__hash__ = str.__hash__
@@ -1313,7 +1313,7 @@ Shouldn't that be 100?
1313
1313
> First, tabs are replaced (from left to right) by one to eight spaces such that the total number of characters up to and including the replacement is a multiple of eight <...>
1314
1314
* So the "tab" at the last line of `square` function is replaced with eight spaces, and it gets into the loop.
1315
1315
* Python 3 is kind enough to throw an error for such cases automatically.
1316
-
1316
+
1317
1317
**Output (Python 3.x):**
1318
1318
```py
1319
1319
TabError: inconsistent use of tabs and spaces in indentation
@@ -1697,7 +1697,7 @@ a += [5, 6, 7, 8]
1697
1697
1698
1698
* The expression `a = a + [5,6,7,8]` generates a new list and sets `a`'s reference to that new list, leaving `b` unchanged.
1699
1699
1700
-
* The expression `a + =[5,6,7,8]` is actually mapped to an "extend" function that operates on the list such that `a` and `b` still point to the same list that has been modified in-place.
1700
+
* The expression `a += [5,6,7,8]` is actually mapped to an "extend" function that operates on the list such that `a` and `b` still point to the same list that has been modified in-place.
1701
1701
1702
1702
---
1703
1703
@@ -1731,7 +1731,7 @@ UnboundLocalError: local variable 'a' referenced before assignment
1731
1731
a += 1
1732
1732
return a
1733
1733
```
1734
-
1734
+
1735
1735
**Output:**
1736
1736
```py
1737
1737
>>> another_func()
@@ -2127,7 +2127,7 @@ Why did `Yo()._Yo__honey` worked? Only Indian readers would understand.
2127
2127
2128
2128
---
2129
2129
2130
-
## Section: Miscallaneous
2130
+
## Section: Miscellaneous
2131
2131
2132
2132
2133
2133
### ▶ `+=` is faster
@@ -2272,7 +2272,7 @@ nan
2272
2272
### ▶ Minor Ones
2273
2273
2274
2274
* `join()` is a string operation instead of list operation. (sort of counter-intuitive at first usage)
2275
-
2275
+
2276
2276
**💡 Explanation:**
2277
2277
If `join()` is a method on a string then it can operate on any iterable (list, tuple, iterators). If it were a method on a list, it'd have to be implemented separately by every type. Also, it doesn't make much sense to put a string-specific method on a generic `list` object API.
2278
2278
@@ -2369,8 +2369,8 @@ If you have any wtfs, ideas or suggestions, please share.
2369
2369
2370
2370
You can use these quick links for Twitter and Linkedin.
0 commit comments