question about True values
Mike Kent
mrmakent at cox.net
Wed Oct 25 15:14:59 EDT 2006
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.
More information about the Python-list
mailing list