1

I'm getting -1 as output for -2//4.

print(-2//4)

1 Answers1

2
-2 divided by 4 == -0.5

In Python 3 the // operator produces the floor of the result

Floor will bring the number to the next lower integer

You are working with negative numbers, hence -1 is less than 0

 -2 / 4
>> -0.5

 math.floor(-0.5)
>> -1

 -2 // 4
>> -1
Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65
  • 1
    "In Python 3 the `//` operator calls a `math.floor()` on the result" - no it doesn't. It produces the floor of the exact result of the division, rather than calling `math.floor` on anything. This matters due to avoiding floating-point rounding. – user2357112 Jan 21 '19 at 00:02