A, b= 1, 2 assigns the maximum value in a and B two variables to C (1) General notation if a>b:c = Aelse:c = B (2) expression C = A If a>b else B (3) Two-dimensional list c = [B,a][a>b] (4) logical Assignment c = (A>b and [a] or [b])  Analysis: 1, 2 for the basic syntax of the program does not discuss 3: First a>b value is true or false, while in Python the default value of True is 1False, the default value is 0. can be c = [B, a] or [B, a], that is, from the list by the index of the way to take the value to C. 4: First in Python, the result returned for the logical operator and, or:and:x, and y is the value that determines the result of the expression. According to the "short-circuit" principle, when X is true, the true and false of the expression is determined by the value of Y, all return y, and if X is False, the x is returned without the judgment of Y. Or:x or Y when X is true directly returns the value of x, when x is False, Y is true, the value of Y is returned, and Y is returned when all is false. So when in the formula allele: When A>b is true: A>b and [A] is true, not in or judgment, return [a] when A>b is false: A>b and [A] is false, return [b] to the list [a] or [b] by subscript 0 to take a value, get a or B.
Multiple ways to If-else in Python