How to check whether a key already exists in a dict in Python since version 2.6?
自2.6版起,如何检查Python字典中是否已存在密钥?
If d
is a dict()
, you can directly test whether a key k
is in d
in Python by the in
keyword like
如果d
是dict()
,则可以通过in
关键字dict()
直接测试键k
是否在python中的d
中。
if k in d:
..
Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。
翻译自: https://www.systutorials.com/in-python-how-to-check-whether-a-key-already-exists-in-a-dict/