[Tutor] validation
Alan Gauld
alan.gauld at btinternet.com
Mon Aug 27 14:00:44 CEST 2007
"Kent Johnson" <kent37 at tds.net> wrote
>> if type(x) == type(int()):
>>
> 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
I knew I should be able to use int but I tried to be too clever
and used type(int) which of course returns 'type type'. So I
used the default int() constructor which returns zero...
For some reason I never thought of simply comparing type()
to int... doh!
Thanks Kent,
Alan g.
More information about the Tutor
mailing list