Rules of Python operators

Like most programming languages, Python has operators whose function is simple at first glance, but actually much more complicated when you think about how they interact with the type system. Even a purely numeric operator like - has to deal with various combinations of integers and floating point numbers, as well as booleans (some operators treat these as 0 and 1), and + also has to deal with strings, and does it allow sequences? Bitwise, equality and comparison each have their own rules.

Is it documented anywhere exactly what the rules are? I don't mean tutorials or suggestive heuristics, but an explicit, exact list of all the rules? What you'd need if you were implementing a dialect of Python 3? doesn't say, and the source code is not optimized for this use case.

1 answer