question about True values
Steve Holden
steve at holdenweb.com
Wed Oct 25 19:05:21 EDT 2006
skip at pobox.com wrote:
> John> I'm a little confused. Why doesn't s evaluate to True in the first
> John> part, but it does in the second? Is the first statement something
> John> different?
>
> >>> s = 'hello'
> >>> s == True
> False
> >>> if s:
> ... print 'hi'
> hi
>
> s is not equal to the boolean object True, but it also doesn't evaluate to
> the string class's "nil" value. Each of the builtin types has such an
> "empty" or "nil" value:
>
> string ""
> list []
> tuple ()
> dict {}
> int 0
> float 0.0
> complex 0j
> set set()
>
> Any other value besides the above will compare as "not false".
>
And today's question for the novices is: which Python type did Skip miss
from the above list?
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list