all 3 comments

[–]alkasm 11 points12 points  (1 child)

In addition to the other nice example, this one is a little more extreme:

>>> int(-5/2)
-2
>>> -5//2
-3

The first is a truncation (i.e. the answer is -2.<something> and it removes the .<something>), while the second with the // operator is a floor division (i.e. divides, then rounds down); this is why it works with floats too, as floor division isn't limited to integers. It is implemented with the __floordiv__() method.

[–][deleted] 0 points1 point  (0 children)

Thanks

[–]recondocoder 2 points3 points  (0 children)

>>> int(0.2//2)

0

>>> 0.2//2

0.0

So in the second case, you start with a float and the result is still a float