python - Automatic int to float conversion -
m = 10 x = 5 val = 1 print(type(val)) in range(1, x+1): val = (val * (m + i)) / (i) print(type(val)) print(val) here val of type int in loop getting converted float although performing integer integer division. why so?
you have use: //
val = (val * (m + i)) // (i) and val remain being integer
the behavior of / changed this: https://www.python.org/dev/peps/pep-0238/
the operator module docs give hint separation between true division (returning float) , floor division returns floor , therefore int
Comments
Post a Comment