"prasad rao" <[email protected]> wrote

2==True
False

It is an unexpected result to me.
I thought any value other than 0 is True.

Any value of non zero is treated as True in a boolean context.
But aq test of equality with a boolean value is not a boolean context.
For equiality you have to compare like with like, and you do that
by taking the boolean value of the number using bool()

So:

if 2: print 'True'
else: print 'False'

will print true
but

if 2 == True: print 'True'
else: print 'False'

will print False.
The two tests are not identical.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to