Home

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.

[note: for the or operator, the short circuit is done if first operand
is True]

A+

Laurent.

PS. See http://en.wikipedia.org/wiki/Truth_table or google for boolean
logic tables.

previous
next

Re: The Modernization of Emacs: terminology buffer and keybinding
Re: Checking if elements are empty
RE: sorting a list numbers stored as strings
Re: introspection and functions
Re: default constructor
Dzieci Niczyje
Akogo
Niechciane i Zapomniane
Kidprotect
Podaruj Zycie