Monday, April 27, 2009

Bizarre Python behavior

A redditor pointed this out, but I'm having difficulty locating the link now:

Identity can be quite surprising in Python:

>>> x = 'a'
>>> y = 'a'
>>> x is y
True
>>> x = ' a'
>>> y = ' a'
>>> x is y
False

1 comment:

  1. Well, you cannot rely on "is" when you really want "==".
    I discuss this very issue here:
    http://www.artima.com/weblogs/viewpost.jsp?thread=240781

    ReplyDelete