+ 2
Why print(-5//2) give - 3 not - 2 ?
6 odpowiedzi
+ 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.
+ 3
It is always the next left integer on the number line.
+ 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#
+ 2
#Simple logic
#points to Remeber : 2>1>0> -1>-2>-3>
#Floor division // gives integer value .
a = -7//2
print(a)
#output : -4
+ 1
You might be interested in this thread
https://www.sololearn.com/Discuss/3065059/?ref=app
and this blog post:
https://shanereilly.net/posts/modulo-operator-in-c++-and-JUMP_LINK__&&__python__&&__JUMP_LINK/
+ 1
Thanks guys that was helpful ✨