4 ms·
(I-=-1)
- raymondh 7y agoEarlier post: https://twitter.com/raymondh/status/1131103570856632321 https://twitter.com/raymondh/status/1131103570856632321
- ThePadawan 7y agoI just learned that Python allows overriding __isub__ separately from __sub__ and the same for __iadd__ [0]. Really interesting! [0] https://docs.python.org/3/reference/datamodel.html#object.__isub__ https://docs.python.org/3/reference/datamodel.html#object.__...
- mixedmath 7y agoThank you. I never thought to consider the possibility of making these be separate. Interesting.
- metalliqaz 7y agoWhy was he surprised that it works? -1 is a perfectly normal integer and -= is a perfectly valid operator.
- ImpressiveWebs 7y agoHe wasn’t surprised it worked, he was surprised someone used it. At least that’s how I took it.
- seasoup 7y agoI think that while people wouldnt be surprised that i -= -1 works, formatted as i-=-1 it's unclear what each - is doing, likely someone did it because it looks nice and symmetrical, as opposed to i+=1
- supereggbert 7y agoProbably because in js if i="1" then i+=1 results in i="11" but i-=-1 results in i=2