- 1

What is the answer for 5/2 and 5//2 ?

28th May 2017, 5:17 AM
Ajay J
Ajay J - avatar
3 Respuestas
+ 4
5/2 is a simple, float division - it will give you a float as a result, in this case 2.5 5//2 is a floor division. It gives you the largest integer which is smaller than 2.5 - so in this case 2 Floor division should NOT be confused with rounding or truncating. For negative numbers it still shows the largest integer smaller than the result of "normal" equation. So 5//2 = 2, but 5//-2 = -3 (-3 is the largest int, smaller than -2.5) -5//2 = -3 -5//-2 = 2
28th May 2017, 6:59 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
Hello, you are using "//" to take an integer from it. When you do need exact solution , you must use "/". For ex. 10//9 == 1 an usable integer 10/9 == 1,09... which we don't usually need in python.
28th May 2017, 7:03 AM
Ali
Ali - avatar
- 1
why we take 5/2is2.5 but in floor division 5//2 is 2
28th May 2017, 5:22 AM
Ajay J
Ajay J - avatar