'is' tests for identity (variable references the same memory location) while '==' tests for equality.  Though it's probably best to use 'is' with more complex classes and not the simpler built-in types like integers.<div>
<br></div><div>See how 'is' works for lists below:</div><div><br></div><div><div>>>> l1 = [1,2,3,4]</div><div>>>> l3 = [1,2,3,4]</div><div>>>> l1 == l3</div><div>True</div><div>>>> l1 is l3</div>
<div>False</div><div>>>> l2 = l1</div><div>>>> l1 is l2</div><div>True</div><div><br></div><div>l1 and l3 are equal because they contain the same elements. But they are not identical because they reference different list objects in memory.  On the other hand, l1 and l2 are identical, so using 'is' in this case tests True. </div>
<div><br></div><div>'is' will be true of the objects tested have the same address in memory.<br><br><div class="gmail_quote">On Thu, May 1, 2008 at 4:10 AM, Gary Herron <<a href="mailto:gherron@islandtraining.com" target="_blank">gherron@islandtraining.com</a>> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Good Z wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8x;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
I am having problem in using is. Here is what i am doing.<br>
</blockquote>
<br></div>
Short answer:  Use == for equality.    Don't use "is".  Ever!  (Especially if you are a newbie.)<br>
<br>
Longer answer:  In a dozen years of programming Python, the only time I use "is" is when testing for something like  if x is None<br>
but, even then<br>
 if x == None<br>
works just as well, and in any case, there is usually a better way.  (See below.)<br>
<br>
Don't use "is" until you can explain the following<br>
>>> 11 is 10+1<br>
True<br>
>>> 100001 is 100000+1<br>
False<div><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8x;border-left:1px #ccc solid;padding-left:1ex">
<br>
x=''<br>
if x is None or x is '':<br>
        return 1<br>
</blockquote>
<br></div>
Both None and an empty string (and empty lists, empty dictionaries, empty sets, and numeric values of 0 and 0.0) all evaluate a False in an if statement, so the above if statement can be written as<br>
<br>
 if not x:<br>
     return 1<br>
<br>
If you have to test for None, just do<br>
 if not x:<br>
<br>
If you have to differentiate between a value of None and something that evaluates to False (e.g., and empty list) then do<br>
 if x is None:<br>
   # handle None explicitly<br>
 elif not x:<br>
   # handle empty list<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8x;border-left:1px #ccc solid;padding-left:1ex"><div>
<br>
The above statement does not return value 1.<br>
<br>
If i changed the above check to<br>
if x == None or x == '':<br>
        return 1<br>
Now it works fine.<br>
<br>
Any idea. What is happening here. I am using python 2.4.4 on ubuntu.<br>
<br>
Mike<br>
<br>
------------------------------------------------------------------------<br></div>
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. <<a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ%20" target="_blank">http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ%20</a>> <br>


------------------------------------------------------------------------<br>
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</blockquote>
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>| _ | * | _ |<br>| _ | _ | * |<br>| * | * | * |
</div></div>