story
Most of the numbers I encounter start as integers and most of the calculations I need are floating-point. This language behavior saves me from sprinkling "* 1.0" everywhere on my code, or from introducing extremely subtle bugs.
And the integer division is always there, one character away:
print(1//2 * 1000) # 0The Python3's operator '/' (on numbers) is defined to return a float, and it'll convert any integer parameters as required. The same is true for other operators, like 'True + True' being 2.
Because of these definitions, you should consider the operators as explicit conversions. 'total / sum' is less explicit than 'total / float(sum)', but still clear enough.
And about guidelines, there are others that fit this case:
Simple is better than complex.
Flat is better than nested.
Readability counts.
[...] practicality beats purity.
PS: I think you made an important argument and I'm glad you did it, even though I disagree with it. I fail to see why you are getting downvotes.I went to check out the operation and it seems a on two ints returns an int if the power is a nonnegative int, and a float if it's negative nonzero, in both 2.7 and 3. I didn't expect this kind of inconsistency from python, really.
>>> type(2 ** 1)
<type 'int'>
>>> type(2 ** -1)
<type 'float'>
I guess it does follow the last line of the guidelines there, though. Looking at this power example, the division returning float now is actually an increase in consistency.But if I was writing it I would space the "1/2" into "1 / 2".
The first says half to me (ok, until I pause and realise it is code I am interpreting), while the second is 1 divided by 2.