3 ms·
"the expression evaluates to true if both return True, but then why is the result thrown out" Actually, the result is not thrown out: the && operator produces
by leokote 16y ago
"the expression evaluates to true if both return True, but then why is the result thrown out"
Actually, the result is not thrown out: the && operator produces the value of its first operand if the first operand is falsy, otherwise it produces the value of the second operand.
For what it's worth, there's also a procedural reading of "foo() && bar()" along the lines of "fill out this form AND win a prize!".
- psyklic 16y agoI wrote 'thrown out' because the statement is "A && B;" -- the result is unused due to the terminating semicolon.