发布时间:2019-08-30 08:33:10编辑:auto阅读(2235)
In Python, you can use the in operator to check if a key exists in a dictionary.
test.pydef main():
fruits = {
'apple':1,
'orange':2,
'banana':3
}
#if key 'apple' exists in fruits?
if 'apple' in fruits:
print(fruits['apple'])
if __name__ == '__main__':
main()
Output
1
P.S Tested with Python 3.4.3
Note
has_key() is deprecated in favor of key in d.
上一篇: 【脚本】python中wmi介绍和使用
下一篇: python -- 计算 平方,乘方,平
51568
51147
41665
38422
32909
29881
28601
23563
23493
21841
1991°
2704°
2265°
2188°
2641°
2207°
2960°
4887°
4724°
3361°