At 08:40 PM 7/18/2008, Kent Johnson wrote:
On Fri, Jul 18, 2008 at 4:45 PM, Dick Moores <[EMAIL PROTECTED]> wrote:
> At 12:38 PM 7/18/2008, Kent Johnson wrote:
>>
>> On Fri, Jul 18, 2008 at 2:25 PM, Dick Moores <[EMAIL PROTECTED]> wrote:
>> > At 10:03 AM 7/18/2008, Kent Johnson wrote:
>> >>
>> >> On Fri, Jul 18, 2008 at 11:32 AM, Dick Moores <[EMAIL PROTECTED]> wrote:
>> >> > if x == 0:
>> >> > return False
>> >> > else:
>> >> > return True
>> >>
>> >> Could be just
>> >> return x!=0
>> >
>> > I see this works, but it's Greek to me. HOW does it work? And why is it
>> > better than what I had? Is it faster? Or what?
>>
>> x != 0 is an expression. The value of that expression is either True
>> or False and is returned as the function result.
>
> Huh. Brand new to me. Thanks.
>
>> It is better because
>> it is concise and idiomatic and has exactly the same result as yours.
>
> Is it time to quote this again?
No :-)
Aw, isn't it good to read it every so often? And I'll bet there are
Tutorees out there who have never seen it.
> In [15]: import this
> The Zen of Python, by Tim Peters
>
> Explicit is better than implicit. <--
My way is explicit. It creates a value, either true or false, and
returns it. Nothing is hidden.
OK, I'll give you that.
> Readability counts. <--
Personally I think my way is more readable. It says what it means
without any fluff. IMO it is explicit, readable, concise and to the
point.
Well, readability is in the eye of the reader. Also, because I lived
in Japan 30 years, I could throw a concise, explicit, and
to-the-point Japanese sentence at you that you wouldn't understand at all.
Maybe this will help you understand, it does the same thing:
value = x != 0
return value
I understand now, and will probably start using such things
as return x != 0, if grumpily at first -- then I'll begin to
think they're cool.
value = (x != 0)
return value
is clearer, IMO.
Thanks for your guidance, Kent.
Dick
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor