Why print(-5//2) give - 3 not - 2 ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why print(-5//2) give - 3 not - 2 ?

24th Sep 2022, 1:47 PM
🌻Emàâââ🌻
🌻Emàâââ🌻 - avatar
6 Answers
+ 5
Python takes a very literal view of its definition of floor division. Floor division returns the nearest integer that is equal to or less than the division result. The division result would be -5/2 = -2.5 Since -2.5 is not an integer, Python looks for the next lower integer, and that value is -3.
24th Sep 2022, 2:22 PM
Brian
Brian - avatar
+ 3
It is always the next left integer on the number line.
24th Sep 2022, 7:49 PM
Oma Falk
Oma Falk - avatar
+ 2
# operator will divide the first argument by the second and round the result down to the nearest whole number making it equivalent to the math.floor() function#
24th Sep 2022, 2:28 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
#Simple logic #points to Remeber : 2>1>0> -1>-2>-3> #Floor division // gives integer value . a = -7//2 print(a) #output : -4
24th Sep 2022, 6:30 PM
KARAN SINGH D
KARAN SINGH D - avatar
+ 1
Thanks guys that was helpful ✨
24th Sep 2022, 10:39 PM
🌻Emàâââ🌻
🌻Emàâââ🌻 - avatar