Short-circuiting evaluation that you can't understand even if you look up the Japanese name. The name is cool and the function is also cool, so make a note so that you don't forget it.
This seems to happen in some cases when defining a conditional expression. To summarize briefly
Sometimes some conditional expressions are only executed halfway
That is. It may be easier to understand if you look at the table (explanation of beginners bare, lol) where the conditions of True or False are set.
For example, when the conditional expression looks like this.
if condition 1 or condition 2:
print('Yahho')
At this time, if the center is connected by or and condition 1 is true, the code in if will be executed regardless of the value on the right side.
** When proceeding with only the result of condition 1 regardless of condition 2, python3 seems to proceed without executing condition 2.
test.py
>>>def ReturnsTrue():
print('ReturnsTrue() was called')
return True
>>>def ReturnsFalse():
print('ReturnsFalse() was called')
return False
>>ReturnsTrue()
#ReturnsTrue() was called
#True
>>>ReturnsFalse()
#ReturnsFalse() was called
#False
>>>ReturnsFalse() or ReturnsTrue()
#ReturnsFalse() was called
#ReturnsTrue() was called
#True
# ReturnsFalse()Should not be executed.
>>> ReturnsTrue() or ReturnsFalse()
#ReturnsTrue() was called
#True
#If you change or to and, everything should be done.
>>> ReturnsTrue() and ReturnsFalse()
#ReturnsTrue() was called
#ReturnsFalse() was called
#False
It is just a beginner's memo writing. .. .. It is sloppy and difficult to understand, but please comment if you are interested. Let's think together.
It's a moment when you can see the creator's intentions, such as thorough efficiency improvement of python3, and it's fun to study computer languages.
And if you study python on the Internet and in English, you will definitely come back with deep knowledge of computer science.
In Japanese, I get the impression that it ends with something like "This way the code will run !!".
Recommended Posts