+ 2

what is the difference between division(/) and floor division (//) in Python?

help through description with an example

10th Jul 2017, 7:35 PM
Gaurav Sharma
Gaurav Sharma - avatar
3 ответов
+ 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
10th Jul 2017, 7:43 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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)
10th Jul 2017, 7:44 PM
Maya
Maya - avatar
0
maya I m a little bit confused from ur answer
10th Jul 2017, 7:47 PM
Gaurav Sharma
Gaurav Sharma - avatar