Python Dictionary DataStructure which method d[] or d.get()?

后端 未结 5 736
栀梦
栀梦 2020-12-16 11:43

While Using Python Dictionary DataStructure (which contains key-value pair) if i want to retrieve some value from my Dictionary i have two options d[\'\'] and g.get(\'key

5条回答
  •  隐瞒了意图╮
    2020-12-16 12:05

    If 'key' does not exist in the dictionary,

    d['key']

    will throw a KeyError, while

    d.get('key')

    will return None.

提交回复
热议问题