4 ms·
The difference between function add and operator plus are solely in the resulting parsing tree. Chaining pluses together is the same as adding arguments to add.
by keymone 7y ago
The difference between function add and operator plus are solely in the resulting parsing tree. Chaining pluses together is the same as adding arguments to add. Proving correctness of operators and stuff is just not something I do when I write python code.
- moefh 7y ago> Chaining pluses together is the same as adding arguments to add No, chaining multiple pluses together in Python (as in most widely-used programming languages) is exactly the same as doing multiple two-argument additions, and is not the same as doing a multiple-argument addition. You can see that in this Python code: n = 2.0 ** 53 print("(1)", n + 1 + 1) print("(2)", (n + 1) + 1) print("(3)", n + (1 + 1)) the line (1) has the same result as line (2), but is different from (3). That's because addition of floating point numbers is only defined for two numbers and is not associative, so `n+1+1` is parsed as `(n+1)+1` and not some magical three-argument floating point addition, which would give the same result as (3).
- keymone 7y agoirrelevant edge cases chaining pluses is the same as adding arguments to add watch: 1+1+1 == add(1,1,1) == 3 you dont have to be so pedantic about implementation quirks, it's not going to become important in your lifetime, unless you consider this comment thread important, in which case, congrats.