Python运算符优先级

pin*_*ker 1 python operators

我应该如何在Python中解释这句话(根据运算符优先级)?

c = not a == 7 and b == 7
Run Code Online (Sandbox Code Playgroud)

作为c = not (a == 7 and b == 7)c = (not a) == 7 and b == 7

谢谢

Ash*_*ary 5

使用dis模块:

>>> import dis
>>> def func():
...     c = not a == 7 and b == 7
...     
>>> dis.dis(func)
  2           0 LOAD_GLOBAL              0 (a)
              3 LOAD_CONST               1 (7)
              6 COMPARE_OP               2 (==)
              9 UNARY_NOT           
             10 JUMP_IF_FALSE_OR_POP    22
             13 LOAD_GLOBAL              1 (b)
             16 LOAD_CONST               1 (7)
             19 COMPARE_OP               2 (==)
        >>   22 STORE_FAST               0 (c)
             25 LOAD_CONST               0 (None)
             28 RETURN_VALUE  
Run Code Online (Sandbox Code Playgroud)

所以,它看起来像:

c = (not(a == 7)) and (b == 7)
Run Code Online (Sandbox Code Playgroud)