Change operator precedence in Python
问题 I have overloaded some Python operators, arithmetic and boolean. The Python precedence rules remain in effect, which is unnatural for the overloaded operators, leading to lots of parentheses in expressions. Is there a way to "overload" Python's precedences? 回答1: You can cheat that mechanism in this way: Override all operators to not do the calculations but create list of instructions wrapped in some object. Add your own bracket operator (ie. as a _ function). Example: >>> a = MyNumber(5); b =