Hello,
I have just started learning python, so please bear with me if my question sounds very basic. (Or please point me to a relevant forum in such a case)
Let's say I have the code
The result is rounded off to 1, instead of 1.5 because of integer division.
So my question is, how do I explicitly declare that I want a variable to be of floating point type? If its a preassigned value, then I can say
But what about the case above? The only way I could think of is to say
Thanks in advance.
I am using Python 2.5 on WinXP.
I have just started learning python, so please bear with me if my question sounds very basic. (Or please point me to a relevant forum in such a case)
Let's say I have the code
Code:
L = [1,2] average = (sum(L))/len(L) print average
So my question is, how do I explicitly declare that I want a variable to be of floating point type? If its a preassigned value, then I can say
Code:
a = 0.5
Code:
L = [1,2] average = (sum(L) * 1.0)/len(L) print average
I am using Python 2.5 on WinXP.
Comment