admin管理员组

文章数量:1404774

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?

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?

Share Improve this question asked Mar 10 at 11:54 An5DramaAn5Drama 7471 gold badge4 silver badges13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

a if b else c if d else e

means

a if b else (c if d else e)

and not

(a if b else c) if d else e

本文标签: pythonHow do conditional expressions group from right to leftStack Overflow