Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The division change is good. I have a hard time understanding why you'd want

    3/2 = 1
as the default behaviour.


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.


> If the user enters "4", you get an int back.

No, it always returns a float in Python 3. 4/2 gives 2.0.


Users 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.


And if they do want integer division, they have to remember // and %.


It's bad and it does not make your point. In P2 you always get an int, in P3 you always get a float.


a = x // 2




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: