mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
[python] Clarify setdefault, as per #234
This commit is contained in:
parent
750b2a2f21
commit
1405dc6387
@ -224,7 +224,7 @@ filled_dict.get("four") #=> None
|
||||
filled_dict.get("one", 4) #=> 1
|
||||
filled_dict.get("four", 4) #=> 4
|
||||
|
||||
# "setdefault()" method is a safe way to add new key-value pair into dictionary
|
||||
# "setdefault()" inserts into a dictionary only if the given key isn't present
|
||||
filled_dict.setdefault("five", 5) #filled_dict["five"] is set to 5
|
||||
filled_dict.setdefault("five", 6) #filled_dict["five"] is still 5
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user