Change operator precedence in Python

后端 未结 2 1152
猫巷女王i
猫巷女王i 2021-01-17 12:52

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 lo

2条回答
  •  迷失自我
    2021-01-17 13:39

    No. It's part of the python language itself. Thats how the language parses.

    Official quote: Evaluation order

    Python evaluates expressions from left to right. Notice that while evaluating an assignment, the right-hand side is evaluated before the left-hand side.

    Other quotes:

    Python:Basics:Numbers and operators

    When performing mathematical operations with mixed operators, it is important to note that Python determines which operations to perform first, based on a pre-determined precedence. This precedence follows a similar precedence to most programming languages.

    Python Programming/Operators

    Note that Python adheres to the PEMDAS order of operations.

提交回复
热议问题