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