Using Python's judgment statement to simulate a triple-eye operation _python

Source: Internet
Author: User

The following is a little similar to the three mesh operation, but not the same, really do not know how to draw up the title, the first is the title bar, we all know that there is no three-eye operation in Python, but and/or a bit similar to the three-mesh operation:
and/or

Use the expression logical relationship with and or separately, can also group and use, usage as follows
and

If a value is False (false, ', [], {}, None ...) Returns the first false value if all values are true returns the last truth
or

If or any of the values are true, returns this value immediately if all the values are false, or returns the last False value
Example

result = ' Test ' and true # result = True result
= ' test ' and ' ortest ' # result = ortest result
= False and ' Ortest ' # result = False result
= ' and None # result = ' result

= ' or ' hall ' # result = Hall result
= False or None # result = None result
= ' test ' or ' nottest ' # result = Test

To simulate a triple-mesh operation using a single line if else

Result if true/false else fresult if is true, results are result, and when false the results are Fresult

result = ' Test ' if True else ' don't test ' # result = ' Test ' result
= ' test ' if False Else ' not test ' # result = ' Not Te St

Related Article

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.