最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How do conditional expressions group from right to left? - Stack Overflow

programmeradmin8浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论