When I first looked at Python, I thought the logic operator was different from other languages, so I recorded it.
There are three logical operations of Python: and, or, not. to correspond with, or, or not respectively.
Strictly speaking, the operand of a logical operator should be a Boolean expression. But Python has a more flexible approach to this.
Even if operands are numbers, the interpreter treats them as "expressions".
A Boolean value of 1,0 for a number other than 0 is a Boolean value of 0.
In Python, the empty string is false and the Non-empty string is true. The Non-zero number is true.
For and operator A and B:
As long as the expression on the left is true, the value returned by the entire expression is the value of the right expression, otherwise, the value of the left expression is returned
For or operator A or B:
As long as the expression on the left is true, the value returned by the entire expression is the value of the left expression, otherwise, the value of the right expression is returned
For not operator not a:
Returns False if A is True. If A is False, it returns TRUE.
Example:
Suppose the variable A is ten, and B is 20.
(A and B) return 20.
(A or B) returns 10.
Not (A and B) returns False
#coding: utf-8 test1 = test2 = 0 test3 = ' ' test4 = ' i ' Print test1 and Test3 #resu lt = ' Print test3 and test1 #result = ' Print test1 and test4 #result = ' The ' a ' print test4 and test1 #result = the print test1 or test2 #result = test1 or test3 #result = print Test3 or test4 #result = "" "Print test2 or test4 #result =" The "the" "a" test1 or test4 #result = print test4 or test1 #result = "Fir St "Print test2 or test3 #result = ' Print test3 or test2 #result = 0