[Tutor] question re type()

Dave Kuhlman dkuhlman at rexx.com
Sat Oct 27 20:34:56 CEST 2007


On Sat, Oct 27, 2007 at 01:03:18PM +0100, Alan Gauld wrote:
> 
> "Dick Moores" <rdm at rcblue.com> wrote
> 
> > if type(n) == 'int' or type(n) == 'long':
> >   do something
> 
> don't use strings
> 
> if type(n) == int
> 
> Or just use an instance of the same type:
> 
> if type(n) == type(42)

Calling type(n) for any integer seems to return the same object. 
I checked with id().

So, should we be using:

    if type(n) is type(42)

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?

Dave
    

> 
> Alan G.
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman


More information about the Tutor mailing list