mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-11-23 06:03:07 +03:00
added some clarification on the default value for dictionary.get
This commit is contained in:
parent
2e805c8c02
commit
fe5f72d868
@ -200,6 +200,10 @@ filled_dict.values() #=> [3, 2, 1]
|
|||||||
filled_dict["four"] #=> KeyError
|
filled_dict["four"] #=> KeyError
|
||||||
|
|
||||||
# Use get method to avoid the KeyError
|
# Use get method to avoid the KeyError
|
||||||
|
filled_dict.get("one") #=> 1
|
||||||
|
filled_dict.get("four") #=> None
|
||||||
|
|
||||||
|
# The get method supports a default argument when the value is missing
|
||||||
filled_dict.get("one", 4) #=> 1
|
filled_dict.get("one", 4) #=> 1
|
||||||
filled_dict.get("four", 4) #=> 4
|
filled_dict.get("four", 4) #=> 4
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user