logoalt Hacker News

p1anecrazytoday at 1:31 PM1 replyview on HN

> The classic example is division: in Python 2, 1 / 2 is 0; while in Python 3 it is 0.5.

Can someone kindly explain this?

edit: I misread it as “In Python 2 2.1/2 is 0, while in Python 3 it is 0.5”


Replies

smoetoday at 1:35 PM

From long ago memory: in Python 2, 1 / 2 did integer division. You had to do something like 1 / 2.0 if you wanted floating point division.

show 1 reply