Home >Backend Development >Python Tutorial >Summary of Python's logical operators and
I suddenly became interested in the recognition of verification codes recently, and then I studied some information on image recognition and processing. One of the image processing is about font refinement and skeleton extraction, but this algorithm is not available in Java. Code implementation, most of the so-called Java version codes are very poor or not effective at all. During the search, I saw a detailed skeleton lifting algorithm implemented in python. The effect is very good, so I thought of rewriting this python implementation. It's good to turn it into Java... But, actually, I don't understand python, so I first went to w3c to read the python syntax, and then started to rewrite it... The problem occurred... when I encountered the logical operator and in the source program At that time, I hesitated... Let's take a look at the explanation of and in w3c:
布尔"与" - 如果x为False,x and y返回False,否则它返回y的计算值。
After seeing this concise explanation, I was shocked... What exactly is it talking about... What does this have to do with logical AND? Relationship... How come the definition of logical AND in Python is so weird... Forget it, just use if else to translate this paragraph and forget it... But then the source program The statements xx and xx and xx appeared in it. It would be easy to use if else to translate it... I suddenly thought how could a normal person's brain predict the meaning of this expression if it followed this logic... python Logical AND shouldn't be weird, but this explanation should be weird...I reorganized my thoughts...
The definition of logical AND (&&) in Java is very clear, and the explanation is as follows :
与:a & b :当a,b同时为true时,a&b为true,否则为false逻辑与:a && b,当a为false时,那么a && b就直接返回false,不会对b再进行判断,因为当a为false时候,无论b为何值,表达式a && b根据与的定义都将是false..但是如果a为true,则需要进一步计算b的值,根据b的值不同,表达式a && b的最终值也不同.
After comparing w3c’s explanation, I found that they were talking about the same thing. But w3c’s explanation is somewhat misleading. It overemphasizes that the value of the expression is x or y. It downplays the meaning of the expression. It gives people the illusion that the value of the logical AND is not the AND, but the value of a or b under certain circumstances..
[Related recommendations]
1. Python and, or and and-or syntax summary
2. Analysis of the usage of and and or in python
3 . Detailed introduction to the actual usage of and and or in Python
4. Sharing an example tutorial on the operation logic of and / or in Python
5. Python: Examples of logical judgments and operators
6. Basic content of Python: operators
The above is the detailed content of Summary of Python's logical operators and. For more information, please follow other related articles on the PHP Chinese website!