what is this?
jay at jaydorsey.com
Sat Nov 1 22:38:21 CET 2003
Herbert Fritsch wrote:
>>>>a = 3
>>>>b = 4
>>>>b / 2 + a
>>>>b / (2.0 + a)
> There must be something wrong. I' running the new Suse 9.0.
Not really. Think of the order of operations in mathematics.
Multiplication and division are ranked higher than addition. Using
parentheses for grouping is higher (before) mulitplication and division.
4 / 2 + 3 yields 2 + 3 yields 5
4 / (2.0 + 3)
Python coerces the 3 into a floating point number, so lets write all
these as floating points:
4.0 / (2.0 + 3.0)
Order of operations says do the parentheses first:
4.0 / 5.0 yields 0.8000000000000004
Theres a listing of Pythons order of operations somewhere in the
documentation on python.org (couldn't find it with a quick search).
More information about the Python-list