Alan Gauld wrote:
> "Michael" <[EMAIL PROTECTED]> wrote
>> trying to use the Type() function but I cannot work out how to check 
>> the
>> return value? Caomparing it to 'int' or 'str' isn't working,
> 
> The easiest way is to compare to another type:
> 
> x = 42
> if type(x) == type(int()):
> 
> or even
> 
> if type(x) == type(2):

For the built-in types, since Python 2.2 the familiar name (int, str, 
float, list, dict, set) *is* the type and you can compare to that 
directly, e.g.:

In [13]: type(3)==int
Out[13]: True
In [14]: type([]) == list
Out[14]: True

Kent
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to