python中的三目运算符

    技术2022-07-11  77

    python中的三目运算符

    众所周知,在java中的三目运算符如下。

    int result = (3 > 2) ? 1:0

    但是在python中时支持上面的写法的,得用到以下写法。

    result = 1 if 3>2 else 0 #优先级顺序 1if 3 > 2 2 、result = 10
    Processed: 0.011, SQL: 9