Comparing variable types
Andrew Bennetts
andrew-pythonlist at puzzling.org
Sat Oct 25 22:45:47 EDT 2003
On Sat, Oct 25, 2003 at 10:36:03PM -0400, Kill Bill wrote:
> type(i) == "<type 'float'>"
> this always returns false. How come?
> type(i)returns <type 'float'> if i is a float so why isn't == working?
Because "<type 'float'>" is a string :)
You want
import types
type(i) == types.FloatType
or
type(i) == type(1.0)
or in 2.2 and later you can simply do
type(i) == float
-Andrew.
More information about the Python-list
mailing list