Equality and identity fun with python

Published at 18, February 2009, author art. Tags: python, tips

>>> assert( int(0) is not long(0) )
>>> assert( int(0) == long(0) )

So, never write like this:

if var is 0:
    print 'Cool!'

Because if type(var) == 'long' it does not work.

Comments

Subscribe on this post's comments

permalink

18, February 2009, owner of http://aeriman.blogspot.com/ said:

Попробуй assert(type(var).name == 'long')

permalink

19, February 2009, owner of http://drj11.wordpress.com/ said:

See also Perils of x is 1.

If you wish to leave comment, please, identify yourself and then come back to this page.