0
The different between get and setdefault
here's a coding: dict = {1:"a",2:"b",3:"c"} test_1 = dict.get(4,"d") print(test_1) test_2 = dict.setdefault(5,"e") print(test_2) print(dict) ============================ the result of print(dict) contain 5:"e". Is that means, the different between get and setdefault is that setdefault would creat a key and value and get only retrun the default value if the dictionary hasnt contain the key? Thank you so much! (sorry for my clumsy english.)
1 Answer
+ 8
https://stackoverflow.com/questions/7423428/JUMP_LINK__&&__python__&&__JUMP_LINK-dict-get-vs-setdefault#:~:text=The%20difference%20between%20the%20two,list%20only%20when%20it's%20unset.&text=So%20setdefault%20is%20around%2010,than%20you%20can%20with%20setdefault%20.