python: dict.get()方法
dict.get() 函数基本构造get(...)D.get(k[,d]) -> D[k] if k in D, else d.d defaults to None.举例说明如果输入的key 在dict中,会返回其对应的key值,否则会返回一个定义的参数d>>> dict = {'1':'one','2':'two','3':'three'}>>> dict.get(
·
dict.get() 函数基本构造
get(...)
D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
举例说明
如果输入的key 在dict中,会返回其对应的key值,否则会返回一个定义的参数d
>>> dict = {'1':'one','2':'two','3':'three'}
>>> dict.get('2',0)
'two'
>>> dict.get('4',0)
0
>>> dict.get('4','false')
'false'
更多推荐
已为社区贡献11条内容
所有评论(0)