[Python-ideas] Break the dominance of boolean values in boolean context

Ned Batchelder ned at nedbatchelder.com
Wed Sep 14 02:59:07 CEST 2011


On 9/12/2011 4:20 PM, Lukas Lueg wrote:
> Summing all up, I really think that we should break the dominance of 
> bool() and take a look at how we can implement boolean contexts 
> without relying on boolean values all the time. 
I was surprised to find that any() returns True or False, regardless of 
the values it encounters.  Conceptually, these two are the same (where S 
is a sequence S0, S1, S2, ..., Sn):

     any(S)

     S0 or S1 or S2 or ... or Sn

They are equivalent except that if Sx is the first true-ish value, the 
first will return True while the second returns Sx.  Why shouldn't any() 
also return Sx?

--Ned.



More information about the Python-ideas mailing list