3 ms·
The division change is good. I have a hard time understanding why you'd want 3/2 = 1 as the default behaviour.
by yen223 13y ago
The division change is good. I have a hard time understanding why you'd want
3/2 = 1
as the default behaviour.
- deleted 13y ago[deleted]
- TylerE 13y agoImagine the following (admittedly bad, minimalistic to make my point) code x = int(input(">>> ")) a = x / 2 append_int_to_magical_db(a) If the division does a "naturaL" thing, you suddenly have a float "polluting" your integer algorithm, but it's _not consistent_. If the user enters "4", you get an int back. If they enter 5, you get a float.
- takluyver 13y ago> If the user enters "4", you get an int back. No, it always returns a float in Python 3. 4/2 gives 2.0.
- meowface 13y agoUsers of Python 3 and up will just have to remember that the result of any division will be a float. It's a breaking change, yes, but in general I think it's a good one.
- nhaehnle 13y agoAnd if they do want integer division, they have to remember // and %.
- dagss 13y agoa = x // 2
- masklinn 13y agoIt's bad and it does not make your point. In P2 you always get an int, in P3 you always get a float.