question about True values
Paul Rubin
http
Wed Oct 25 15:10:19 EDT 2006
More information about the Python-list mailing list
Wed Oct 25 15:10:19 EDT 2006
- Previous message (by thread): question about True values
- Next message (by thread): question about True values
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
John Salerno <johnjsal at NOSPAMgmail.com> writes: > 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? No. True and False are boolean values, where booleans are a different data type from strings, just like strings are different from integers. >>> if s: print 'hi' converts s to a boolean during evaluation. That is, it's the same as if bool(s): print 'hi' bool(s) is a function that converts s to a bool. If s is a string, bool(s) is true if s is nonempty, false otherwise. A comparable thing with integers: suppose x = 3.1 then "x == 3" is false, but "int(x) == 3" is true.
- Previous message (by thread): question about True values
- Next message (by thread): question about True values
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list