Feature suggestion -- return if true

Chris Angelico rosuav at gmail.com
Mon Apr 11 22:44:19 EDT 2011


On Tue, Apr 12, 2011 at 12:20 PM, James Mills
<prologic at shortcircuit.net.au> wrote:
> On Tue, Apr 12, 2011 at 12:18 PM, Jason Swails <jason.swails at gmail.com> wrote:
>> This is only true if n < 5.  Otherwise, the first returns None and the
>> second returns False.
>
> Which is why I said:
>
> return expr or None
>
> But hey let's argue the point to death!

That's still not equivalent. "return expr or None" will always
terminate the function. The OP's request was for something which would
terminate the function if and only if expr is non-false.

Chris Angelico



More information about the Python-list mailing list