John Salerno wrote:
> I'm a little confused. Why doesn't s evaluate to True in the first part,
> but it does in the second? Is the first statement something different?
>> >>> s = 'hello'
> >>> s == True
> False
> >>> if s:
> print 'hi'
>>> hi
> >>>
>> Thanks.
Excellent question! This should help:
>>> s = "Hello"
>>> s
'Hello'
>>> bool(s)
True
>>> s == True
False
The value of s is not equal to the value of True. But, the *boolean*
value of s is True, since it is not 0 or an empty string. The python
'if' statement evaluates the boolean value of the condition expression.