bool constructor is inconsistent?

Discussion in 'Python' started by Neal Becker, Sep 10, 2010.

  1. Neal Becker

    Neal Becker Guest

    IN [3]: bool('False')
    Out[3]: True

    In [4]: int('32')
    Out[4]: 32
     
    Neal Becker, Sep 10, 2010
    #1
    1. Advertising

  2. 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
     
    Stefan Schwarzer, Sep 10, 2010
    #2
    1. Advertising

  3. On Fri, Sep 10, 2010 at 2:35 PM, Stefan Schwarzer
    <> 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.
     
    David Robinow, Sep 10, 2010
    #3
  4. 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
     
    Steven D'Aprano, Sep 11, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Giulio
    Replies:
    9
    Views:
    1,064
    Patrick Kowalzick
    Jun 25, 2003
  2. Brett Irving
    Replies:
    3
    Views:
    3,346
    John Harrison
    Jun 29, 2003
  3. lallous
    Replies:
    5
    Views:
    8,858
    David Harmon
    Jan 23, 2004
  4. Generic Usenet Account
    Replies:
    10
    Views:
    2,320
  5. Luke Allardyce
    Replies:
    2
    Views:
    105
    Luke Allardyce
    Apr 18, 2014
Loading...

Share This Page