(no) fast boolean evaluation ? missing NOT
laurent.pointal at limsi.fr
Fri Aug 3 11:57:03 CEST 2007
Stef Mientki a écrit :
> 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'
> print 'I''ll never print this'
> Ive been here 4
> I knew it was True
> 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.
[note: for the or operator, the short circuit is done if first operand
PS. See http://en.wikipedia.org/wiki/Truth_table or google for boolean
More information about the Python-list