此代码块的结果
items = ['j','ak',(4,5)]
tests = ['j','as',(4,5)]
for key in tests:
for item in items:
if item==key:
print key,'was found'
break
else:
print key,'not found'
是:
j被发现了
没有找到
(4,5)被发现
以及这段代码的结果
items = ['j','ak',(4,5)]
tests = ['j','as',(4,5)]
for key in tests:
if key in items:
print key+' was found'
else:
print key+' not found'
是:
j被发现了
如未找到
现在,问题是:为什么(4,5)在“测试”和“项目”中没有比较第二个块,而任何一个块的结果应该相同?它是“in”运算符的东西吗?