P
P
Puma Thailand2018-03-23 07:27:16
Python
Puma Thailand, 2018-03-23 07:27:16

Are the rest of the python if statements executed if the result is already clear from the first statement?

I did not immediately find something in the documentation at this point
. If there is such an
if a and b and c:
where a, b, c are very very heavy functions,
will b, c be executed if a returned false?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2018-03-23
@opium

It's easy to check:

>>> def return_false1():
...     print('run 1')
...     return False
...
>>> def return_false2():
...     print('run 2')
...     return False
...
>>> def return_false3():
...     print('run 3')
...     return False
...
>>>
>>> if return_false1() and return_false2() and return_false3():
...     print('I newer executed')
...
run 1
>>>

and about lazy calculations in Python have already been said above.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question