as we've seen in previous exampleswe can then look up values in the dictionary by requesting key inside square brackets if the key is not in the dictionaryit will raise an exceptionstocks["goog"( stocks["rim"traceback (most recent call last)file ""line in keyerror'rimwe canof coursecatch the keyerror and handle it but we have other options rememberdictionaries are objectseven if their primary purpose is to hold other objects as suchthey have several behaviors associated with them one of the most useful of these methods is the get methodit accepts key as the first parameter and an optional default value if the key doesn' existprint(stocks get("rim")none stocks get("rim""not found"'not foundfor even more controlwe can use the setdefault method if the key is in the dictionarythis method behaves just like getit returns the value for that key otherwiseif the key is not in the dictionaryit will not only return the default value we supply in the method call (just like get does)it will also set the key to that same value another way to think of it is that setdefault sets value in the dictionary only if that value has not previously been set then it returns the value in the dictionaryeither the one that was already thereor the newly provided default value stocks setdefault("goog""invalid"( stocks setdefault("bbry"( )( stocks["bbry"(