Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > bool constructor is inconsistent?

Reply
Thread Tools

bool constructor is inconsistent?

 
 
Neal Becker
Guest
Posts: n/a
 
      09-10-2010
IN [3]: bool('False')
Out[3]: True

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

 
Reply With Quote
 
 
 
 
Stefan Schwarzer
Guest
Posts: n/a
 
      09-10-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
 
Reply With Quote
 
 
 
 
David Robinow
Guest
Posts: n/a
 
      09-10-2010
On Fri, Sep 10, 2010 at 2:35 PM, Stefan Schwarzer
<(E-Mail Removed)> 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.
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      09-11-2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
Copy constructor hides default constructor Aire C++ 3 01-25-2004 05:47 PM
java like constructor calling constructor lallous C++ 5 01-23-2004 11:52 PM
calling a constructor within a constructor Brett Irving C++ 3 06-29-2003 10:43 AM
why it's not possible calling constructor from constructor? Giulio C++ 9 06-25-2003 03:56 PM



Advertisments