当前位置: 首页 > 工具软件 > FORC > 使用案例 >

python中for c in s是什么意思_这个python语法发生了什么? (c == c in s)

钱劲
2023-12-01

有人只是向我展示了这个奇怪的

python语法示例.为什么[4]工作?

我会期望它评估[5]或[6],这两个都不工作.有没有一些过早的优化在这里不应该是?

In [1]: s = 'abcd'

In [2]: c = 'b'

In [3]: c in s

Out[3]: True

In [4]: c == c in s

Out[4]: True

In [5]: True in s

---------------------------------------------------------------------------

TypeError Traceback (most recent call last)

in ()

----> 1 True in s

TypeError: 'in ' requires string as left operand, not bool

In [6]: c == True

Out[6]: False

 类似资料: