▲ | qsort 9 days ago | |||||||
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. | ||||||||
▲ | nyrikki 9 days ago | parent | next [-] | |||||||
In C, that is really because Unary minus (negation) has precedence over binary operations.
https://en.cppreference.com/w/cpp/language/operator_arithmet...
The same doesn't apply to, !! Which is applied as iterated binary operations (IIRC)I am pretty sure the decriment operator came around well after that quirk was established. | ||||||||
| ||||||||
▲ | j2kun 9 days ago | parent | prev [-] | |||||||
Also worth noting that `1 - -2` works and produces 3 in C because the space breaks the operator. |