classdict(object):
"""
dict() -> new empty dictionary
dict(mapping) -> new dictionary initialized from a mapping object's
(key, value) pairs
dict(iterable) -> new dictionary initialized as if via:
d = {}
for k, v in iterable:
d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
"""defclear(self): # real signature unknown; restored from __doc__""" D.clear() -> None. Remove all items from D. """passdefcopy(self): # real signature unknown; restored from __doc__""" D.copy() -> a shallow copy of D """pass @staticmethod # known casedeffromkeys(*args, **kwargs): # real signature unknown""" Create a new dictionary with keys from iterable and values set to value. """passdefget(self, *args, **kwargs): # real signature unknown""" Return the value for key if key is in the dictionary, else default. """passdefitems(self): # real signature unknown; restored from __doc__""" D.items() -> a set-like object providing a view on D's items """passdefkeys(self): # real signature unknown; restored from __doc__""" D.keys() -> a set-like object providing a view on D's keys """passdefpop(self, k, d=None): # real signature unknown; restored from __doc__"""
D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise,
raise a KeyError.
"""passdefpopitem(self, *args, **kwargs): # real signature unknown"""
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order.
Raises KeyError if the dict is empty.
"""passdefsetdefault(self, *args, **kwargs): # real signature unknown"""
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
"""passdefupdate(self, E=None, **F): # known special case of dict.update"""
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]
"""passdefvalues(self): # real signature unknown; restored from __doc__""" D.values() -> an object providing a view on D's values """passdef__class_getitem__(self, *args, **kwargs): # real signature unknown""" See PEP 585 """passdef__contains__(self, *args, **kwargs): # real signature unknown""" True if the dictionary has the specified key, else False. """passdef__delitem__(self, *args, **kwargs): # real signature unknown""" Delete self[key]. """passdef__eq__(self, *args, **kwargs): # real signature unknown""" Return self==value. """passdef__getattribute__(self, *args, **kwargs): # real signature unknown""" Return getattr(self, name). """passdef__getitem__(self, y): # real signature unknown; restored from __doc__""" x.__getitem__(y) <==> x[y] """passdef__ge__(self, *args, **kwargs): # real signature unknown""" Return self>=value. """passdef__gt__(self, *args, **kwargs): # real signature unknown""" Return self>value. """passdef__init__(self, seq=None, **kwargs): # known special case of dict.__init__"""
dict() -> new empty dictionary
dict(mapping) -> new dictionary initialized from a mapping object's
(key, value) pairs
dict(iterable) -> new dictionary initialized as if via:
d = {}
for k, v in iterable:
d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
# (copied from class doc)
"""passdef__ior__(self, *args, **kwargs): # real signature unknown""" Return self|=value. """passdef__iter__(self, *args, **kwargs): # real signature unknown""" Implement iter(self). """passdef__len__(self, *args, **kwargs): # real signature unknown""" Return len(self). """passdef__le__(self, *args, **kwargs): # real signature unknown""" Return self<=value. """passdef__lt__(self, *args, **kwargs): # real signature unknown""" Return self<value. """pass @staticmethod # known case of __new__def__new__(*args, **kwargs): # real signature unknown""" Create and return a new object. See help(type) for accurate signature. """passdef__ne__(self, *args, **kwargs): # real signature unknown""" Return self!=value. """passdef__or__(self, *args, **kwargs): # real signature unknown""" Return self|value. """passdef__repr__(self, *args, **kwargs): # real signature unknown""" Return repr(self). """passdef__reversed__(self, *args, **kwargs): # real signature unknown""" Return a reverse iterator over the dict keys. """passdef__ror__(self, *args, **kwargs): # real signature unknown""" Return value|self. """passdef__setitem__(self, *args, **kwargs): # real signature unknown""" Set self[key] to value. """passdef__sizeof__(self): # real signature unknown; restored from __doc__""" D.__sizeof__() -> size of D in memory, in bytes """pass
__hash__ = None
四、常用的字典操作
插入新的键值
# 插入新的键值>>> a
{'age': 18, 'name': 'gm'}
>>> a['job'] = '运维'>>> a
{'age': 18, 'job': '运维', 'name': 'gm'}
修改字典某键的值
# 修改字典某键的值>>> a
{'age': 18, 'name': 'gm'}
>>> a['name']='root'>>> a
{'age': 18, 'name': 'root'}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程