[Tutor] True and 1 [was Re: use of the newer dict types]
Alan Gauld
alan.gauld at btinternet.com
Sun Jul 28 01:53:46 CEST 2013
On 27/07/13 20:17, Jim Mooney wrote:
> Since I admitted to still being a bit confused, I though it out, and:
>
>>>> [[[[[L]]]]] == L
> True
>
> False propagates outward, since each containing bracket also contains
> an empty object.
Its not that false propagates out, it's how Python does a comparison of
lists. The rules for equality are what matter here not the rules of
boolean conversion.
comparison operations return -1, 0 or 1.
The boolean conversion of that result is effectively the inverse of the
return value - ie 0 implies equality is true, -1 or 1 implies False.
Try:
>>> cmp([L],L)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list