0

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

1
  • 2
    Have you considered that he could not know the meaning of the word short-circuiting? Commented Nov 3, 2014 at 9:04

3 Answers 3

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).

Sign up to request clarification or add additional context in comments.

Comments

2

This is called short-circuiting, and Python does support it. You can read an explanation in the docs.

Comments

1

Yes, Python short-circuits the evaluation of Boolean expressions.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.