"is" and "=="

Carl Banks imbosol-1047402492 at aerojockey.com
Tue Mar 11 12:44:10 EST 2003


Dagur P?ll Ammendrup wrote:
> I was wondering when == should be used and when "is". I like using "is" 
> when comparing strings and stuff but maybe I shouldn't?


Try this at the prompt:

>>> "ab" is "a"+"b"
0


You should use "is" only when explicitly checking if a and b are same
object (that is, same location in memory, and same .id()).  Otherwise,
use ==.


-- 
CARL BANKS




More information about the Python-list mailing list