Q:

Why I get this 0 as answer for (1/10) in Python?

I am trying this in Python 2.7 Interpreter.
>>> print 1/10  
0  
>>> print float(1/10)  
0.0  
>>> print 1/5  
0  
>>> a = 1/5  
>>> a  
0  
>>> float(a)  
0.0  
>>>   

I want a value in floating point when I divide.  Any idea on the logic behind this zero out put and please let me know how to do it correctly.

A:

The float conversion is happening after the integer division. Try this:
>>> print(1.0/10)
0.1

A:

In Python 2.x, by default / means integer (truncating) division when used with two integer arguments. In Python 3.x, / always means float division, and // always means integer division. You can get the Python 3.x behaviour in 2.x using:
from __future__ import division

See PEP 238 for a full discussion of the division operators.

A:

You need to do something like:
print (1.0/10)

When you do:
print 1/10

It is evaluating it as 0 because it is treating it as an integer.
And when you do:
print float(1/10)

You take the stuff inside the float() and evalute that first so in essence you get:
print float(0)

Which would be 0.0

