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'

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
相关资源
相似解决方案