integer division

Pythonは型を明示的に定義しないので,見落としがちだ.

tsz=100

tszinv=1/tsz

として,tszinv=0.01を期待すると,実はtszinvはゼロになってしまう.これは整数同士の演算結果は整数になるためだ.実数で演算結果を得るには

tszinv=1/float(tsz)

とすればよい.

tsz=100

tszinv=1/tsz

If you expect tszinv=0.01, it is wrong. Actually, tszinv=0. This is because the operation between integers results in an integer. In order to get a floating result, you should write

tszinv=1/float(tsz)

In python, we usually do not declare types of variables, and tend to overlooks this kind of mistakes.