This article mainly introduces the python keyword and or usage examples. This article provides the implementation code directly. If you need a friend, you can refer to and in python to calculate the expression from left to right. If all values are true, returns the last value. If false exists, the first value is returned.
Or is also a calculated expression from left to return the first true value.
The Code is as follows:
IDLE 1.2.4
>>> 'A' and 'B'
'B'
>>> ''And 'B'
''
>>> 'A' or 'B'
'A'
>>> ''Or 'B'
'B'
Usage similar to the three-object expression: bool? A: B
The Code is as follows:
>>> A = 'first'
>>> B = 'second'
>>> 1and a or B # is equivalent to bool = true.
'First'
>>> 0 and a or B # is equivalent to bool = false.
'Second'
>>> A =''
>>> When 1and a or B # a is false, an error occurs.
'Second'
>>> (1and [a] or [B]) [0] # Security usage, because [a] cannot be false, at least one element
''
>>>