Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   bool constructor is inconsistent? (http://www.velocityreviews.com/forums/t733006-bool-constructor-is-inconsistent.html)

Neal Becker 09-10-2010 06:23 PM

bool constructor is inconsistent?
 
IN [3]: bool('False')
Out[3]: True

In [4]: int('32')
Out[4]: 32


Stefan Schwarzer 09-10-2010 06:35 PM

Re: bool constructor is inconsistent?
 
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

David Robinow 09-10-2010 07:56 PM

Re: bool constructor is inconsistent?
 
On Fri, Sep 10, 2010 at 2:35 PM, Stefan Schwarzer
<sschwarzer@sschwarzer.net> wrote:
> 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.
> ...

I've always felt that if a humorous post needs a smiley, that it's not funny.
However, there is the risk of being misunderstood.

Steven D'Aprano 09-11-2010 12:25 AM

Re: bool constructor is inconsistent?
 
On Fri, 10 Sep 2010 14:23:34 -0400, Neal Becker wrote:

> IN [3]: bool('False')
> Out[3]: True
>
> In [4]: int('32')
> Out[4]: 32


Where is the inconsistency? bool('False') returns the same result as for
any other non-empty string:

>>> bool("not true")

True
>>> bool("no")

True
>>> bool("incorrect")

True
>>> bool("wrong")

True
>>> bool("Faux")

True
>>> bool("Falsch")

True
>>> bool("Falso")

True
>>> bool("偽")

True
>>> bool("Ложно")

True



Treating the string "False" as identical to the named global False would
be inconsistent.


--
Steven


All times are GMT. The time now is 08:23 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.