Skip to content

Commit 43355e2

Browse files
committed
Merge branch 'master' into 3.0
2 parents 45a2cb5 + 8135cbb commit 43355e2

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,7 +2932,7 @@ nan
29322932
29332933
#### 💡 Explanation:
29342934
2935-
`'inf'` and `'nan'` are special strings (case-insensitive), which when explicitly typecasted to `float` type, are used to represent mathematical "infinity" and "not a number" respectively.
2935+
`'inf'` and `'nan'` are special strings (case-insensitive), which when explicitly typecast-ed to `float` type, are used to represent mathematical "infinity" and "not a number" respectively.
29362936
29372937
---
29382938
@@ -2964,13 +2964,29 @@ nan
29642964
+ `++a` parses as `+(+a)` which translates to `a`. Similarly, the output of the statement `--a` can be justified.
29652965
+ This StackOverflow [thread](https://stackoverflow.com/questions/3654830/why-are-there-no-and-operators-in-python) discusses the rationale behind the absence of increment and decrement operators in Python.
29662966
2967+
* Have you ever heard about _the space-invader operator_ in Python?
2968+
```py
2969+
>>> a = 42
2970+
>>> a -=- 1
2971+
>>> a
2972+
43
2973+
```
2974+
It is used as an alternative incrementation operator, together with another one
2975+
```py
2976+
>>> a +=+ 1
2977+
>>> a
2978+
>>> 44
2979+
```
2980+
**💡 Explanation:**
2981+
This prank comes from [Raymond Hettinger's tweet](https://twitter.com/raymondh/status/1131103570856632321?lang=en). The space invader operator is actually just a malformatted `a -= (-1)`. Which is equivalent to `a = a - (- 1)`. Similar for the `a += (+ 1)` case.
2982+
29672983
* Python uses 2 bytes for local variable storage in functions. In theory, this means that only 65536 variables can be defined in a function. However, python has a handy solution built in that can be used to store more than 2^16 variable names. The following code demonstrates what happens in the stack when more than 65536 local variables are defined (Warning: This code prints around 2^18 lines of text, so be prepared!):
29682984
```py
29692985
import dis
29702986
exec("""
29712987
def f():
29722988
""" + """
2973-
""".join(["X"+str(x)+"=" + str(x) for x in range(65539)]))
2989+
""".join(["X" + str(x) + "=" + str(x) for x in range(65539)]))
29742990
29752991
f()
29762992

0 commit comments

Comments
 (0)