Re: Implicit conversion to boolean in if and while statements

Discussion in 'Python' started by Chris Angelico, Jul 15, 2012.

  1. On Sun, Jul 15, 2012 at 6:34 PM, Andrew Berg <> wrote:
    > Converting 0 and 1 to False and True seems reasonable, but I don't see
    > the point in converting other arbitrary values.


    It's for convenience. Unfortunately, not all languages treat all types
    the same way. It's very handy, though, to be able to use

    if not foo: foo = some_initializer

    when foo starts out as, say, None. Or []. Or, in fact, any other "empty" value.

    ChrisA
     
    Chris Angelico, Jul 15, 2012
    #1
    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. J Leonard
    Replies:
    4
    Views:
    12,833
    Mark Space
    Jan 19, 2008
  2. John Crichton
    Replies:
    6
    Views:
    283
    John Crichton
    Jul 12, 2010
  3. Metre Meter
    Replies:
    7
    Views:
    429
    Metre Meter
    Aug 6, 2010
  4. Andrew Berg
    Replies:
    143
    Views:
    1,494
    Chris Angelico
    Feb 16, 2013
  5. Stefan Behnel
    Replies:
    0
    Views:
    203
    Stefan Behnel
    Jul 15, 2012
Loading...

Share This Page