小编los*_*g12的帖子

此示例中三元运算符的优先级是什么?

>>> count = 0
>>> for c in "##.#.":
...     count = count + 1 if c == '.' else 0
... 
>>> print(count)
1
>>> count = 0
>>> for c in "##.#.":
...     count = count + (1 if c == '.' else 0)
... 
>>> print(count)
2
Run Code Online (Sandbox Code Playgroud)

为什么第一个示例不打印出计数器 2?

python conditional-operator operator-precedence

3
推荐指数
1
解决办法
972
查看次数