[Tutor] is gotchas?

wesley chun wescpy at gmail.com
Tue Nov 7 04:13:08 CET 2006


others already gave good responses, so mine are short.

> 1)where do `is` and `==` yield the same results?

"is" is object identity comparison while
"==" is object value comparison


> 2)where do they not yield the same results?

they give different results when you have two different objects
regardless of the equality of their values.


> 3)is there a special method for `is'.

no, not really. you can use id() and '==' to proxy for is:

a is b <==> id(a) == id(b)


> 4)Pointers to docs are welcome.

http://docs.python.org/lib/comparisons.html
http://docs.python.org/ref/comparisons.html

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list