Use the judgment Statement of Python to simulate the Three-object operation.

Source: Internet
Author: User

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'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.