while true: !!!

Andrew Henshaw andrew_dot_henshaw_at_earthling_dot_net
Tue Dec 19 21:36:49 EST 2000


"Steve Holden" <sholden at holdenweb.com> wrote in message
news:ckJ%5.3097$Yv6.81688 at e420r-atl1.usenetserver.com...
...snip
> I've always tried to discourage students from comparing a Boolean with a
> constant, but it can be difficult to get the point over that (a) can
> evaluate as true even though (a == some_constant) may well evaluate to
> false.
>
> Clearly, if what you have is a Boolean value (i.e. one which can be used
as
> the expression in an "if" statement) then it's adding inefficiency to
> compare it with something, when what should be used is either
>
>     if a:
>
> or
>
>     if not a:
>
> This works quite nicely in Python:
>
> >>> not "forever"
> 0

I had never thought of this before, but it is kind of interesting that
    not 'this is a true string'
doesn't produce
    ''
but instead produces 0.

Similarly, not [0, 1, 2] could produce [] .

In fact, I could see where that might be useful.  On the other hand (to be
consistent), what would
    not []
produce? :)

Also, shouldn't false == false ?
    '' == []
returns 0.
  :)

Well, at least
    (not '') == (not [])
returns 1.


Andrew Henshaw





More information about the Python-list mailing list