Feature suggestion -- return if true

Grant Edwards invalid at invalid.invalid
Tue Apr 12 09:50:23 EDT 2011


On 2011年04月12日, James Mills <prologic at shortcircuit.net.au> wrote:
> On Tue, Apr 12, 2011 at 4:08 PM, Nobody <nobody at nowhere.com> wrote:
>> It should be abundantly clear that this only returns if the expression is
>> considered true, otherwise it continues on to the following statements.
>> Uggh come on guys. We've been over this.
> You cannot make that assumption.

You most certain can. Try it yourself in an interpreter. The
OP's code snippit will not return if expr is false, rather it will
continue executing in the current context:
>>> def foo(expr):
... __temp__ = expr # these two lines are
... if __temp__: return __temp__ # the OP's code snippet
... print "the code snippet did not return"
... 
>>> print foo(9)
9
>>>>>> print foo(0)
the code snippet did not return
None
>>>
-- 
Grant Edwards grant.b.edwards Yow! One FISHWICH coming
 at up!!
 gmail.com 


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /