Python 字典的setdefault()方法

Python 字典的setdefault()方法

setdefault(key[, default])


If  key is in the dictionary, return its value. If not, insert  key with a value of  default and return  defaultdefault defaults to None.

若是键在字典中,返回这个键所对应的值。若是键不在字典中,向字典 中插入这个键,而且以default为这个键的值,并返回 default。default的默认值为None
相关文章
相关标签/搜索