←back to thread

183 points sebg | 1 comments | | HN request time: 0s | source
Show context
benob ◴[] No.43644247[source]
TIL that in python, 1--2==3
replies(1): >>43644397 #
seplox ◴[] No.43644397[source]
It's not a python thing. 1-(-2), distribute the negative.
replies(1): >>43644519 #
qsort ◴[] No.43644519[source]
In most C-like languages that would be a syntax error. E.g. in C and C++ as a rule you tokenize "greedily", "1--2" would be tokenized as "1", "unary decrement operator", "2", which is illegal because you're trying to decerment an rvalue.

Python doesn't have "--", which allows the tokenizer to do something else.

replies(2): >>43645088 #>>43646211 #
1. j2kun ◴[] No.43646211[source]
Also worth noting that `1 - -2` works and produces 3 in C because the space breaks the operator.