python 中问号表达式替代 exper and a or b

    技术2024-11-20  8

    (1) variable = a if exper else b

    (2) variable = exper and b or c

    (3) variable = (exper and [b] or [c])[0]

    a, b = 1, 2 max = a if a > b else b max3 = a > b and a or b max2 = (a > b and [a] or [b])[0] # list print max,max2,max3
    Processed: 0.022, SQL: 9