3
I went to do a calculation on Python 2.7 and got scared when I saw the result:
val = 1 / 16
print(val); # 0
Example in IDEONE
That is, when we make a division where the divided number is less than the divisor, the returned result is zero.
How do I get the result in
float
?Why does Python behave this way?
In Python 3 this changed. From what I read about this change, it was precisely because it made the understanding confusing. Now, in Python 3, the entire division is another operator:
val = 1 // 16
; the two bars//
represent the entire division– Jefferson Quesado