Szabolcs wrote: > Newbie question: > > Why is 1 == True and 2 == True (even though 1 != 2), > but 'x' != True (even though if 'x': works)?
Please check before you post: [E:\Projects]python Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 2==True False >>> Anyway, it helps to think about value domains (in your examples, numbers and strings) as having a single "null" value, and non-null values. The null value is considered False. The non-null values are considered True. The null value for numbers is 0 obviously, and for strings it is '' (the empty string). Non-zero numbers and non-empty strings are considered "True" when used in a boolean expression. --Irmen -- http://mail.python.org/mailman/listinfo/python-list