Puzzled by "is"

Steve Holden steve at holdenweb.com
Sun Aug 12 11:23:26 EDT 2007


Dick Moores wrote:
> On 8/12/07, *Ben Finney* <bignose+hates-spam at benfinney.id.au 
> <mailto:bignose+hates-spam at benfinney.id.au>> wrote:
> 
>     Dick Moores <rdm at rcblue.com <mailto:rdm at rcblue.com>> writes:
> 
>      > At 06:13 PM 8/9/2007, Ben Finney wrote:
>      > >it's entirely left to the language implementation which
>      > >optimisation trade-offs to make, and the language user (that's you
>      > >and I) should *not* expect any particular behaviour to hold between
>      > >different implementations.
>      >
>      > I'm not clear on the meaning of "implementations" here.  Would 2.5
>      > for Windows, Mac, Linux all be different implementations? Would Iron
>      > Python be another? ActivePython?
> 
>     For the purpose of the above statement, you should consider even the
>     same Python on two different machines to be "different
>     implementations". As a programmer writing Python code, you should not
>     expect any "implementation-dependent" behaviour to operate in any
>     particular way.
> 
> 
> So would a programmer EVER use "is" in a script?

Sure. For example, the canonical test for None uses

     x is None

because there is only ever one instance of type Nonetype, so it's the 
fastest test. Generally speaking you use "is" to test for identity (do 
these two expressions reference the same object) rather than equality 
(do these two expressions evaluate to equivalent objects).

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------




More information about the Python-list mailing list