At 09:14 PM 12/15/2004, Tim Peters wrote:
[Brian van den Broek]
> in Marc's check_range thread, I had proposed:
>
> def check_in_range(value):
>
>     in_range = False
>     if 9 < value < 90:
>         in_range = True
>     return in_range
>
> and DogWalker suggested the better:
>
> def check_in_range(value):
>     return 9 < value < 90
>
> As I mentioned, I feel as though I have a mental block getting in the
> way of coming up with code in the smoother fashion of the second snippet
> above.

Don't feel frustrated -- using Boolean expressions idiomatically is
very much a learned skill.  So is adding integers, but *that* got
drilled into you over years, and years, and years.  It won't take
quite as long to sling bools <wink>.

The worst abuse is one you're perhaps not prone to:  having a Boolean
expression e, and then writing

    if e == True:

instead of

    if e:

For some reason, that's extremely common in code written by newcomers
to Pascal.

Not to mention coding examples provided by Microsoft in some help topics! [snip]

Bob Gailer
[EMAIL PROTECTED]
303 442 2625 home
720 938 2625 cell


_______________________________________________
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to