By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,706 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,706 IT Pros & Developers. It's quick & easy.

Re: Use of the "is" statement

P: n/a
Joel Corbin wrote:
Thank you Gary, Cédric, Christian. When *would *one use "is"?
As I said:
The "is" statement should only be used when you want to check of
something is exactly and identical to None like "a is None" or "b is not
None". For everything else you should use == or !=. There are some other
use cases for "is", too. But in general you shouldn't use "is".
Cédric... the problem I was having was purely an issue of comparison.... "if
file.tell() is 0L" was returning False. Strangely enough, "if file.tell() is
0" returns True in the right cases. I assume this is related to the None
Both usages of "is" are wrong. The second case works by accident,
because Python optimized small ints. The int object 0 and some more
objects are a singletons.

Ask yourself if you are interested if f.tell() returns exactly the same
0 object ("is") or a number that is equal to 0 ("==").


Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.