Why print(-5//2) give - 3 not - 2 ?
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.
It is always the next left integer on the number line.
# 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#
#Simple logic #points to Remeber : 2>1>0> -1>-2>-3> #Floor division // gives integer value . a = -7//2 print(a) #output : -4
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-python/
Thanks guys that was helpful ✨
What is input?
Decimal to Hex in C++