(Mar-29-2023, 01:43 AM)Carmazum Wrote: Python only interprets the first statement it detects as True.To be precise, it works top down until (and if) it reach a
if
/elif
that is evaluated as True
or eventually (if present) else
. That may have effect, because some code may be executed even if the condition as whole is False
. In other words, code may be executed while evaluating the condition, even if the result is False
and the respective code block under that condition is not executed.Simplified example
def spam(): print('Inside spam') # just to show that function has been called return False if spam(): print('spam is True') else: print('spam is False')output
Output:Inside spam
spam is False
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs