How to implement the three-object operation in Python

Source: Internet
Author: User
This article mainly introduces how to implement the three-object operation in Python. This article uses the andor operator to simulate the three-object operation. if you need a friend, refer to the three-object operator in C language.

The code is as follows:


Expression? Expr1: expr2; // If expression is true, the value of expr1 is obtained; otherwise, the value of expr2 is obtained.


Python implementation method:

(1) expr = judgment expression and expr1 or expr2

Determines whether the expression is true. if expr1 is true, expr = expr1. if it is False, it is False or expr2, expr = expr2.

If the expression is False, it is converted to False or expr2. in this case, expr = expr2.

As long as both expr1 and expr2 are true, the above equation is equivalent

Expr = judgment expression? Expr1: expr2;

(2) min (x, y) = (x (3) min (x, y = x if x

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.