[Python] How do conditional expressions group from right to left?

Discussão em 'Python' iniciado por Stack, Março 10, 2025.

  1. Stack

    Stack Membro Participativo

    I checked python operator precedence


    Operators in the same box group left to right (except for exponentiation and conditional expressions, which group from right to left).

    ** Exponentiation [5]

    if – else Conditional expression
    ​

    I can understand exponentiation that 2**3**2 is equal to 2**(3**2). But Conditional expression


    conditional_expression ::= or_test ["if" or_test "else" expression]
    ​

    is not one binary operator. I can't give one similar example as **. Could you give one example of "group from right to left" for if Conditional expression?

    Continue reading...

Compartilhe esta Página