Comparing variable types

Emile van Sebille emile at fenx.com
Sat Oct 25 22:48:44 EDT 2003


"Kill Bill" <bill at kill.com> wrote in message
news:bnfbuj$10f3di$1 at ID-198839.news.uni-berlin.de...
> type(i) == "<type 'float'>"

This compares the current type of i to type("string"), which is <type
'str'>.

You can do:
>>> i = 1.3
>>> type(i) == "<type 'float'>"

False
>>> str(type(i)) == "<type 'float'>"
True


> this always returns false.  How come?
> type(i)returns <type 'float'> if i is a float so why isn't == working?
>


What you probably want is:

>>> import types
>>> type(i) == types.FloatType
True
>>>

Emile van Sebille
emile at fenx.com








More information about the Python-list mailing list