目录
- in 与not in在字典中的用法
- 字典内置的get也可以参与一下
in 与not in
In [39] : test_dict = { 'name' : 'insane' }
In [40]: 'name' in test_dict
0ut [40]: True
In [41]: 'name' not in test_dict
Out [41]: False
get用于判断成员存在
In [42]: test_dict = { 'name' : 'insane' }
In [43]: bool(test_dict.get( 'name' ))
out [43]: True
实战
# coding:utf-8
default_dict = {
'a': None, 'b':