+ 3

Excuse me..5//2 quotient is actually 2.5 - a float..but here we take it only 2.Why??sorry new to python-maybe a silly question

22nd Apr 2017, 4:24 PM
Naseef
Naseef - avatar
2 ответов
+ 25
/ will give 2.5 or simply a float // will give floor division i.e 2 or simply will give you integer.
22nd Apr 2017, 4:26 PM
Frost
Frost - avatar
+ 6
in python, 5 / 2 is normal division and will give you 2.5 but 5 // 2 is integer division, so it will take the answer (2.5) and cut off the decimal, so you only get the whole number integer (2) and remember it doesnt round. so like if you use integer division and the answer should be 4.82, it will still give you 4. it wont round to 5
22nd Apr 2017, 4:27 PM
Edward