Home

Advertisement

October 26th, 2009

Surprising: Arithmetic behaviour in Python

  • Oct. 26th, 2009 at 5:34 PM
close up
It is surprising to me. Probably not for all Python programmers.
In [1]: a = 5
In [2]: b = 2
In [3]: a/b
Out[3]: 2
In [4]: float(a)/float(b)
Out[4]: 2.5
And another one, in same line:
 
In [5]: a = float(5)
In [6]: b = float(2)
In [7]: a/b
Out[7]: 2.5
 

Tags: