Perl and Python, a practical side-by-side example.

Ben Finney bignose+hates-spam at benfinney.id.au
Sat Mar 3 02:49:10 EST 2007


Bjoern Schliessmann <usenet-mail-0306.20.chr0n0ss at spamgourmet.com> writes:

> Bruno Desthuilliers wrote:
> > Shawn Milo a écrit :
>
> >>     if recs.has_key(piid) is False:
> > 
> > 'is' is the identity operator - practically, in CPython, it
> > compares memory addresses. You *dont* want to use it here.
>
> It's recommended to use "is None"; why not "is False"? Are there
> multiple False instances or is False generated somehow?

I'd recommend against using "is False" simply because it's more
confusing. This is better::

    if not recs.has_key(piid):      # [1]

Moreover, any 'if' statement expects a boolean expression *anyway*, so
there's no point testing for identity against False. Otherwise, the
following would be just as reasonable::

    if (recs.has_key(piid) is False) is True:

Or perhaps:

    if (((((recs.has_key(piid) is False) is True) is False) is False) is True):


[1]: yes, this is even better written as 'if not piid in recs', but
that's beside the point for this discussion.

-- 
 \                                          "To be is to do"  -- Plato |
  `\                                    "To do is to be"  -- Aristotle |
_o__)                                     "Do be do be do"  -- Sinatra |
Ben Finney




More information about the Python-list mailing list