get(key) 从字典中获取一个key对应的value,返回value
>>> dict1={1:'a',2:'b',3:'c'}
>>> dict1.get(1)
'a'
如果字典里面不存在,则返回一个 NoneType
>>> type(dict1.get(4))
<type 'NoneType'>
如果要求key值不存在,指定另外一个值返回的话
>>> dict1.get(4,'not found')
'not found'
get(key) 从字典中获取一个key对应的value,返回value
>>> dict1={1:'a',2:'b',3:'c'}
>>> dict1.get(1)
'a'
如果字典里面不存在,则返回一个 NoneType
>>> type(dict1.get(4))
<type 'NoneType'>
如果要求key值不存在,指定另外一个值返回的话
>>> dict1.get(4,'not found')
'not found'
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。