Question about mecanism of a check conditions. if ONE or TWO:
Will TWO condition checked, If ONE == True
? Where can I read about this?
Asked
Active
Viewed 189 times
0

George Sh.
- 240
- 1
- 8
-
2Have you considered that he could not know the meaning of the word *short-circuiting*? – Trimax Nov 03 '14 at 09:04
3 Answers
2
In python this is called short-circuiting. Logical expressions are evaluated left to right (taking into account brackets) and execution stops as soon as it is clear what the logical answer will be.
Try this code in the interactive console:
>>> def one():
... print "one called"
... return True
>>> def two():
... print "two called"
... return True
>>> one() or two()
The response will be:
one called
True
The same thing happens with and
(if the first argument is False, the 2nd argument is never evaluated).

Benjamin Hodgson
- 42,952
- 15
- 108
- 157

Tony Suffolk 66
- 9,358
- 3
- 30
- 33
2
This is called short-circuiting, and Python does support it. You can read an explanation in the docs.

Benjamin Hodgson
- 42,952
- 15
- 108
- 157