while true: !!!

gbreed at cix.compulink.co.uk gbreed at cix.compulink.co.uk
Wed Dec 20 07:58:18 EST 2000


In article <t4073164g9shaf at corp.supernews.com>, 
andrew_dot_henshaw_at_earthling_dot_net (Andrew Henshaw) wrote:

> I had never thought of this before, but it is kind of interesting that
>     not 'this is a true string'
> doesn't produce
>     ''
> but instead produces 0.

That also means that "not not" is a "convert to boolean" equivalent.

> Similarly, not [0, 1, 2] could produce [] .
> 
> In fact, I could see where that might be useful.  On the other hand (to 
> be
> consistent), what would
>     not []
> produce? :)

Where would it be useful?

I suppose if not [] still returned 1, at least not not would always return 
a "boolean".  But it would mean you couldn't guarantee the type of not 
performed on a list.

If you want to empty a sequence, but preserve the type, try filter(lambda 
x:0, asequence).

> Also, shouldn't false == false ?
>     '' == []
> returns 0.
>   :)
> 
> Well, at least
>     (not '') == (not [])
> returns 1.

Yes, that's where the existing behaviour comes in useful.  As Python's 
fairly consistent in not expecting truth values to be of any given type, 
it's not as useful as it could be.  But it's still nice to know it's 
there.


                Graham



More information about the Python-list mailing list