`

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 default. default defaults to None.

 

如果键在字典中,返回这个键所对应的值。如果键不在字典中,向字典 中插入这个键,并且以default 为这个键的值,并返回  default default 的默认值为 None

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics