3 ms·
Imagine the following (admittedly bad, minimalistic to make my point) code x = int(input(">>> ")) a = x / 2 append_int_to_magical_db(a) If the div
by TylerE 13y ago
Imagine 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.