[Tutor] question re type()
alan.gauld at btinternet.com
Sun Oct 28 00:57:56 CEST 2007
"Dave Kuhlman" <dkuhlman at rexx.com> wrote
> Calling type(n) for any integer seems to return the same object.
> I checked with id().
I would hope so since they are all of the same type.
It thus makes sense that they all return a reference to
the same type object.
> So, should we be using:
> if type(n) is type(42)
You could, it shouldn't make any difference in this context.
> or, as suggested by Aditya Lal in another message in this thread:
> import types
> if type(n) is types.IntType
> Or, is this a frivolous question that makes no difference?
'is' or == can make a difference in some cases but I don't
think this is one of them.
More information about the Tutor