On Sat, 14 May 2011 00:45:29 -0700, rusi wrote: > On May 14, 12:39 pm, Steven D'Aprano <steve > +comp.lang.pyt...@pearwood.info> wrote: >> On Thu, 12 May 2011 23:46:12 -0700, rusi wrote: >> > Mathematics has existed for millenia. Hindu-arabic numerals (base-10 >> > numbers) have been known for about one millennium The boolean domain >> > is only a 100 years old. Unsurprisingly it is not quite 'first-class' >> > yet: See >> >http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html >> > [Lifted fromhttp://c2.com/cgi/wiki?EqualVsTrueFalse] >> >> Th money-quote as regards using arbitrary objects in truth tests: >> >> [quote] >> All this changed with the introduction of the two-element boolean >> domain {true, false} which provides the vocabulary needed to >> assign values to boolean expressions: 3<4 is a way for writing >> true, 3>4 is a way for writing false, whereas the value of x>0 >> depends on the value of x ... [end quote] >> >> In Python, [1, 2, 3] is another way of writing true, and [] is another >> way of writing false. Similarly with any other arbitrary objects. > > Well so is [1,2] another way of writing True > > And then we get the interesting result that (True = True) is False
I presume you mean to say: ([1, 2] == True) is False that is, that one true value is not equal to another true value. That is correct. However, Python's == operator is not a Boolean Algebra operator. If it were, it would probably be called "material biconditional", or XNOR, and written ↔ or <-> and would be smart enough to recognise that both [1, 2] and True are true. Or possibly dumb enough... the difficulty is that the equality operator knows more about the objects than just their truth value. And furthermore: ([1, 2] and True) == (True and [1, 2]) is also False, again because == is too smart to recognise that the left hand side (True) and the right hand side ([1, 2]) are both true values. It's not that Python bools aren't first class objects, but that Python doesn't have a full set of all 16 possible boolean algebra operators. -- Steven -- http://mail.python.org/mailman/listinfo/python-list