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刪除。