diff options
author | Kyle Partridge <partkyle@gmail.com> | 2013-06-28 13:55:16 -0700 |
---|---|---|
committer | Kyle Partridge <partkyle@gmail.com> | 2013-06-28 13:55:16 -0700 |
commit | fe5f72d868313987cb3d6a55de707876046d912d (patch) | |
tree | 53704ba24614d8fea0dcee188836cf4c28523392 | |
parent | 2e805c8c020719da0aab40987b7c064c864db9c8 (diff) |
added some clarification on the default value for dictionary.get
-rw-r--r-- | python.html.markdown | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/python.html.markdown b/python.html.markdown index 39a2349d..a3ced659 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -200,6 +200,10 @@ filled_dict.values() #=> [3, 2, 1] filled_dict["four"] #=> 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("four", 4) #=> 4 |