[python] Clarify setdefault, as per #234

This commit is contained in:
Adam Brenecki 2013-09-20 19:32:58 +09:30
parent 750b2a2f21
commit 1405dc6387

View File

@ -224,7 +224,7 @@ filled_dict.get("four") #=> None
filled_dict.get("one", 4) #=> 1 filled_dict.get("one", 4) #=> 1
filled_dict.get("four", 4) #=> 4 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", 5) #filled_dict["five"] is set to 5
filled_dict.setdefault("five", 6) #filled_dict["five"] is still 5 filled_dict.setdefault("five", 6) #filled_dict["five"] is still 5