Python Problem III | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Python Problem III

I just discovered another something: Why do you think print(-22 // 10) return -3? Can someone explain this code? Thanks for any response that you make.

7th Jul 2020, 8:28 AM
James Clark I. Vinarao
James Clark I. Vinarao - avatar
3 Answers
+ 4
Just like 『 AVD-01 』 said. "//" Is a floor division operator. Which divides the numbers and return the *floor* of the result. Which is number less than or equal to the answer. In this case -22/10 = -2.2 And floor(-2.2) = -3 And not -2 as (-2 > -2.2)
7th Jul 2020, 9:03 AM
Arsenic - avatar
7th Jul 2020, 8:55 AM
᮴Ridwan_ - avatar
+ 1
It is called floor division, done using // operator When floor dividing, the result of normal division is round off to nearest whole number -22//11 returns -2 as its the nearest whole number, and it never returns -3 I guess
7th Jul 2020, 8:34 AM
A C K - avatar