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

https://docs.python.org/3/library/operator.html


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -