[英] How can I check if a key exists in a dictionary?
假设我有一个关联数组,如下所示:{'key1': 22, 'key2': 42}
.
如何判断字典中是否有key1
个?
假设我有一个关联数组,如下所示:{'key1': 22, 'key2': 42}
.
如何判断字典中是否有key1
个?
if key in array:
# do something
在Python中,关联数组被称为字典,您可以在the stdtypes documentation中了解有关它们的更多信息.