python“设置”和“ in”
我在python中的设置和操作员有一个小问题。为什么索引是“”集合中的,但不是实际值? 代码如下:
sett = {}
sett[10]="a"
sett[12]="b"
sett[31]="c"
print('a' in sett)
print(31 in sett)
输出: 错误的 真的
I've got a little problem with set and in operator in python.Why is the index "in" the set, but not the actual value?
The code is following:
sett = {}
sett[10]="a"
sett[12]="b"
sett[31]="c"
print('a' in sett)
print(31 in sett)
output:
False
True
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当使用“ in”用于字典时,它将通过键而不是值搜索。字典是一系列关键:值集。因此,没有“一个”键,但是有一个“ 31”键。如果您尝试:
这将返回true,因为现在它正在搜索特定键的值。
When using "in" for dictionaries, it is going to search through the keys, not the the values. The dictionary is a series of key:value sets. So the there is no "a" key, but there is a "31" key. If you try:
This will return True because now it is searching the value for a specific key.