explaination for this python floor division ? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

explaination for this python floor division ?

why this code >>>print(11//3) yields 3 ,while that code >>>print(-11//3) yields -4 ?

19th Jan 2020, 2:41 PM
Amgad Elsaiegh
Amgad Elsaiegh - avatar
2 ответов
+ 6
// basically seems to floor the result. 11/3 == 3.666, so 3 (lowered) -11/3== -3.666, so -4 (also lowered)
19th Jan 2020, 2:46 PM
HonFu
HonFu - avatar
+ 6
Because // is not getting rid of the fractional part, it is flooring, it rounds to the closest minimum.
19th Jan 2020, 2:54 PM
SergeiRom