开发者

How to test if a dictionary contains a specific key? [duplicate]

This question already has answers here: Check if a given key already exists in a d开发者_Go百科ictionary (16 answers) Closed 3 years ago.

What's the cleanest way to test if a dictionary contains a key?

x = {'a' : 1, 'b' : 2}
if (x.contains_key('a')):
    ....


'a' in x

and a quick search reveals some nice information about it: http://docs.python.org/3/tutorial/datastructures.html#dictionaries

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜