(no) fast boolean evaluation ? missing NOT

Stef Mientki S.Mientki-nospam at mailbox.kun.nl
Fri Aug 3 13:16:51 CEST 2007


Laurent Pointal wrote:
> Stef Mientki a écrit :
>> <Python>
>> def Some_Function (const):
>>     print 'Ive been here', const
>>     return True
>>
>> A = True
>>
>> if A and Some_Function (4 ):
>>     print 'I knew it was True'
>> else:
>>     print 'I''ll never print this'
>> </Python>
>>
>> <Output>
>> Ive been here 4
>> I knew it was True
>> </Output
>>
>> I was expected that the function would not be called,
>> because A is True.
> 
> When using the *and* operator, the short-circuit evaluation is done if A 
> is False (no need to know the other operand, the result cannot be True). 
> But if A is True, the compiler must evaluate the second parameter to 
> know the expression result.
Sorry you're completely right,
and indeed I must have something very stupid !!

thanks very much
Stef Mientki



More information about the Python-list mailing list