== versus is operators and type()

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Feb 27 05:03:45 EST 2003


Alvaro Figueiredo <alvarof at freeshell.org> wrote in 
news:mailman.1046280868.27016.python-list at python.org:

> As an example, are the two expressions bellow totally equivalent?
> 
> type(arg) is type(0) or type(arg) is type(0.0)
> 
> type(arg) in (type(0), type(0.0))
> 
> Thanks in advance.
> 

Yes, although you should consider using isinstance (unless you need 
backwards compatability with old versions of Python):

    isinstance(arg, (int, float))


-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list