您的位置:首页 > 编程语言 > Python开发

Python字典常见函数

2018-02-21 13:27 218 查看
items()

keys()

values()

get()

pop()

popitem()

update()

setdefault()

D.items() -> a set-like object providing a view on D’s items

D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.

D.pop(k[,d]) -> v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

D.popitem() -> (k, v), remove and return some (key, value) pair as a

2-tuple; but raise KeyError if D is empty.

D.update([E, ]**F) -> None. Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]

If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v

In either case, this is followed by: for k in F: D[k] = F[k]

D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D

参考Python基础(一)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 字典 常见函数