'==' vs. 'is' behavior
François Pinard
pinard at iro.umontreal.ca
Tue Nov 30 11:56:55 EST 1999
First of all, thanks for your replies, all.
"Fredrik Lundh" <fredrik at pythonware.com> écrit:
> according to the eff-bot:
What is "the eff-bot"? I've read about "eff-bot" and "tim-bot" a few
times by now, and thought it was some kind of internal joke in the group,
but begin to think there might be some substance behind the expression! :-)
> foo is None
> type(foo) is type(bar) # same type
> foo is bar # same instance
> use '==' for everything else (unless you know what
> you're doing, of course).
Wise enough. I guess I'll do exactly that. Thanks for the suggestion.
"Tim Peters" <tim_one at email.msn.com> écrit:
> [François Pinard]
> > By the way, is there common wisdom (or rather, maybe,
> > usage-standards-to-be) about using `is' instead of `=='?
> In general, don't -- you'll often end up regretting this cleverness.
I've never been bitten so far, and as long as I do only sensible things,
there is no reason nor fear I would be bitten later. I presume you agree
that Fredrik suggestions, above, are very reasonable?
[Many good explanations and examples not repeated.]
> Clearest and safest: don't use "is" when "==" would suffice.
I'm a bit minimalist while programming. Or, to say the same thing another
way, I rather like Arvo Part's music. When a program source is just
abusing of parentheses without justification (helping `python-mode' _is_
a justification!), it gives me the uncomfortable feeling the author has
never been able to properly sort operator priorities, and probably many
other things as well :-). Of course, I quite agree with you that there
is equilibrium and reason to put in the pondering.
And to be fully honest, I find the "is not" syntactical sugar rather sweet.
It would be a shame not using it, once in a while :-).
nascheme at enme.ucalgary.ca écrit:
> Using `is' interchangably with == is asking for trouble.
Of course. This is why I asked for some sounded advice about how to do
it nicely.
> Your lucky you don't do Lisp.
I don't? :-)
In fact, I like Scheme a lot, and use the Gambit system for some bigger
applications. And, despite with much less pleasure, I sometimes play around
Emacs LISP. If I could get Gambit and Python together, it would be fun!
--
François Pinard http://www.iro.umontreal.ca/~pinard
More information about the Python-list
mailing list