Difference between 'is' and '=='

Max M maxm at mxm.dk
Mon Mar 27 06:56:52 EST 2006


mwql wrote:

> Hey guys, this maybe a stupid question, but I can't seem to find the
> result anywhere online. When is the right time to use 'is' and when
> should we use '=='? 

"is" is like id(obj1) == id(obj2)

 >>> 100+1 == 101
True

 >>> 100+1 is 101
False

They don't have the same id. (Think of id as memory adresses.)

-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

Phone:  +45 66 11 84 94
Mobile: +45 29 93 42 96



More information about the Python-list mailing list