Use the judgment Statement of Python to simulate the Three-object operation.
The operation below is a little similar to the three-object operation, but it is different. I really don't know how to draw up the title. Let's start with this title. We all know that there are no three-object operations in python, however, the and/or operation is similar to the three-object operation:
And/or
The logical relationship and or can be grouped and used separately. The usage is as follows:
And
And, if a value is False (False, '', [], {}, None ...) Returns the first false value. If all values are true, returns the last true value.
Or
If any or value is true, return immediately. If all values are false, or return the last false value.
Example
Result = 'test' and True # result = Trueresult = 'test' and 'ortest' # result = ortestresult = False and 'ortest' # result = Falseresult = ''and None # result = ''result = ''or" Hall "# result = Hallresult = False or None # result = Noneresult = 'test' or 'nottest' # result = test
Use a single line if else to simulate a three-object operation
Result if True/False else fresult if True, the result is result. if False, the result is fresult.
Result = 'test' if True else 'not test' # result = 'test' if False else 'not test' # result = 'not Test'