[EMAIL PROTECTED] a écrit :
> I tried writing a true and false If statement and didn't get
> anything?  I read some previous posts, but I must be missing
> something.  I just tried something easy:
> 
> a = ["a", "b", "c", "d", "e", "f"]
> 
> if "c" in a == True:
>      Print "Yes"
> 
> When I run this, it runs, but nothing prints.  What am I doing wrong?

See other answers for the details. Anyway, since '"c" in a' is already a 
boolean expression, testing the result of the evaluation of this 
expression against a boolean is a pure waste of time. The usual idiom - 
and this is definitively not Python-specific - is:

if "c" in a:
   print "Yes"

Also, in Python (and in some other languages too), there's a notion of 
"something" vs "nothing" - where, in a boolean context, "something" 
evals to true and "nothing" to false. wrt/ Python, the empty string, an 
empty container (list, tuple, dict, set etc), numerical zero's (int or 
float), and of course the None object all eval to false, and most other 
objects eval to true.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to