How to test if a dictionary contains a specific key?

Possible Duplicate:
What is a good way to test if a Key exists in Python Dictionary

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

并快速搜索揭示了一些关于它的好信息:http://docs.python.org/3/tutorial/datastructures.html#dictionaries

链接地址: http://www.djcxy.com/p/28878.html

上一篇: Python检查密钥是否在字典中定义

下一篇: 如何测试字典是否包含特定的密钥?