From d143f972b8a6a43b0e16c3ca4b26bd965e94a2d4 Mon Sep 17 00:00:00 2001 From: mitcom Date: Sun, 6 Oct 2019 13:06:38 +0200 Subject: [PATCH 1/3] Add space-invader operator case --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index be27847..27940e5 100644 --- a/README.md +++ b/README.md @@ -2368,6 +2368,24 @@ nan + `++a` parses as `+(+a)` which translates to `a`. Similarly, the output of the statement `--a` can be justified. + 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. +* There is a lack of incrementation operator known from different languages, but have you ever heard about _the space-invader operator_? + ```py + >>> a = 42 + >>> a -=- 1 + >>> a + 43 + ``` + + + together with another: + ```py + >>> a +=+ 1 + >>> a + >>> 44 + ``` + + **💡 Explanation:** + This prank comes from [Raymond Hettinger's twit](https://twitter.com/raymondh/status/1131103570856632321?lang=en) and it is actually just malformatted `a -= (-1)`. Which is eqivalent to `a = a - (- 1)`. Similar for the `a += (+ 1)` case. + * 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!): ```py import dis From f8acf49d0544108684d3fa66337e14a11bf9c6f1 Mon Sep 17 00:00:00 2001 From: Satwik Kansal Date: Wed, 9 Oct 2019 18:48:41 +0530 Subject: [PATCH 2/3] Update README.md --- README.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 27940e5..c31017e 100644 --- a/README.md +++ b/README.md @@ -2368,23 +2368,21 @@ nan + `++a` parses as `+(+a)` which translates to `a`. Similarly, the output of the statement `--a` can be justified. + 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. -* There is a lack of incrementation operator known from different languages, but have you ever heard about _the space-invader operator_? +* Have you ever heard about _the space-invader operator_ in Python? ```py >>> a = 42 >>> a -=- 1 >>> a 43 ``` - - + together with another: - ```py - >>> a +=+ 1 - >>> a - >>> 44 - ``` - + It is used as an alternative incrementation operator, together with another one + ```py + >>> a +=+ 1 + >>> a + >>> 44 + ``` **💡 Explanation:** - This prank comes from [Raymond Hettinger's twit](https://twitter.com/raymondh/status/1131103570856632321?lang=en) and it is actually just malformatted `a -= (-1)`. Which is eqivalent to `a = a - (- 1)`. Similar for the `a += (+ 1)` case. + 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 eqivalent to `a = a - (- 1)`. Similar for the `a += (+ 1)` case. * 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!): ```py From bef3f2a33db59a65b159dec661c13c36850501f0 Mon Sep 17 00:00:00 2001 From: monujee Date: Fri, 25 Oct 2019 14:28:25 +0530 Subject: [PATCH 3/3] Update README.md Typo corrected. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c31017e..b1354cc 100644 --- a/README.md +++ b/README.md @@ -2336,7 +2336,7 @@ nan #### 💡 Explanation: -`'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. +`'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. --- @@ -2382,7 +2382,7 @@ nan >>> 44 ``` **💡 Explanation:** - 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 eqivalent to `a = a - (- 1)`. Similar for the `a += (+ 1)` case. + 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. * 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!): ```py @@ -2390,7 +2390,7 @@ nan exec(""" def f(): """ + """ - """.join(["X"+str(x)+"=" + str(x) for x in range(65539)])) + """.join(["X" + str(x) + "=" + str(x) for x in range(65539)])) f()