print (1/3)
print (1./3)
I don't see difference between (1/3) and (1./3). When should I use one or the other, and why?
print (1/3)
print (1./3)
I don't see difference between (1/3) and (1./3). When should I use one or the other, and why?
This is done to make sure the output is a floating point number. 1./3 means 1.0 / 3 which would return 0.33333...
1/3 would produce 0 as an integer
EDIT: This is only valid in Python 2
It depends on the Python version you are using:
With the dot you can specify that the number should be treated as floating point number otherwise it will be an integer.
In Python 2 the devision of an integer will result in an integer value. In this case 0.3333 will be rounded to 0. Whereas in Python3 the devision will result in a floating point number never the less the dividend is an integer or a floating point number. In this case it will be in every case 0.3333