gpt4 book ai didi

python - 'not e in c' 与 Python 中的 'e not in c' 有什么不同吗?

转载 作者:IT老高 更新时间:2023-10-28 20:53:20 25 4
gpt4 key购买 nike

Possible Duplicate:
Order of syntax for using ‘not’ and ‘in’ keywords

我的 TA 声称 e not in c 并不总是产生与 not e in c 相同的结果(他没有解释 为什么 虽然)。我从未在任何人的代码中亲自看到过第二种形式(除了他的和解释这两个 等效的书籍),也从未见过两者在行为上有所不同,所以我对这种说法持怀疑态度。通过谷歌没有找到任何东西,我决定来这里。

那么有没有人知道任何关于两者行为不同的案例的信息?

最佳答案

它们完全相同,因为两者实际上都应用了 not in 比较:

In [25]: def func():
'e' not in 'bee'
....:
....:

In [27]: def func1():
not 'e' in 'bee'
....:
....:
In [29]: dis.dis(func)
2 0 LOAD_CONST 1 ('e')
3 LOAD_CONST 2 ('bee')
6 COMPARE_OP 7 (not in)
9 POP_TOP
10 LOAD_CONST 0 (None)
13 RETURN_VALUE

In [30]: dis.dis(func1)
2 0 LOAD_CONST 1 ('e')
3 LOAD_CONST 2 ('bee')
6 COMPARE_OP 7 (not in)
9 POP_TOP
10 LOAD_CONST 0 (None)
13 RETURN_VALUE

关于python - 'not e in c' 与 Python 中的 'e not in c' 有什么不同吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12941287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com