bool constructor is inconsistent?

Stefan Schwarzer sschwarzer at sschwarzer.net
Fri Sep 10 14:35:10 EDT 2010


Hi Neal,

On 2010-09-10 20:23, Neal Becker wrote:
> IN [3]: bool('False')
> Out[3]: True

If you consider strings, only an empty string has a false
value. So the string 'False' which is non-empty, results in
a true boolean value.

For example, you can use

    if my_string:
        ...

to execute some code if the string is not empty.

Stefan



More information about the Python-list mailing list