+ 2
what is the difference between division(/) and floor division (//) in Python?
help through description with an example
3 Réponses
+ 11
Floor division, instead of a proper division result returns *the nearest lowest* integer.
17 / 4 = 4.25
17 // 4 = 4
It has to be remembered also for negative numbers:
17 // 4 = 4
17 // -4 = -5 (nearest lowest of -4.25)
-17 // 4 = -5 (same as above)
-17 // -4 = 4
+ 6
division (/) returns a float and acts as regular math division
floor (//) returns the divisible part as integer without the remainder
5/2 = 2.5
5//2 = 2 (remainder 1)
0
maya I m a little bit confused from ur answer