>>> type({}) <class ‘dict‘> >>> dir(dict) [‘__class__‘, ‘__contains__‘, ‘__delattr__‘, ‘__delitem__‘, ‘__dir__‘, ‘__doc__‘, ‘__eq__‘, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘, ‘__getitem__‘, ‘__gt__‘, ‘__hash__‘, ‘__init__‘, ‘__init_subclass__‘, ‘__iter__‘, ‘__le__‘, ‘__len__‘, ‘__lt__‘, ‘__ne__‘, ‘__new__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__setattr__‘, ‘__setitem__‘, ‘__sizeof__‘, ‘__str__‘, ‘__subclasshook__‘, ‘clear‘, ‘copy‘, ‘fromkeys‘, ‘get‘, ‘items‘, ‘keys‘, ‘pop‘, ‘popitem‘, ‘setdefault‘, ‘update‘, ‘values‘] >>> ‘clear‘清除, ‘copy‘复制, ‘fromkeys‘迭代:值, ‘get‘获取, ‘items‘键值对, ‘keys‘键, ‘pop‘弹出, ‘popitem‘随机弹出, ‘setdefault‘设置默认, ‘update‘更新, ‘values‘值 clear(self): >>> d={‘a‘:1,"b":2} >>> d.clear() >>> d {} copy(self): >>> {‘a‘:1,"b":2}.copy() {‘a‘: 1, ‘b‘: 2} >>> fromkeys(*args, **kwargs): >>> d={} >>> nd=d.fromkeys([1,2,3,4],[5,6,7,8]) >>> d {} >>> nd {1: [5, 6, 7, 8], 2: [5, 6, 7, 8], 3: [5, 6, 7, 8], 4: [5, 6, 7, 8]} >>> get(self, k, d=None): >>> {1:2,2:4,3:6}.get(4,7) 7 >>> items(self): >>> {1:2,2:4,3:6}.keys() dict_keys([1, 2, 3]) >>> {1:2,2:4,3:6}.values() dict_values([2, 4, 6]) >>> {1:2,2:4,3:6}.items() dict_items([(1, 2), (2, 4), (3, 6)]) >>> 可迭代 keys(self): >>> {1:2,2:4,3:6}.keys() dict_keys([1, 2, 3]) >>> {1:2,2:4,3:6}.values() dict_values([2, 4, 6]) >>> {1:2,2:4,3:6}.items() dict_items([(1, 2), (2, 4), (3, 6)]) >>> 可迭代 pop(self, k, d=None): >>> d={1:2,2:4,3:6} >>> d.pop(2) 4 >>> d {1: 2, 3: 6} >>> popitem(self): >>> d={1:2,2:4,3:6} >>> d.popitem() (3, 6) >>> d {1: 2, 2: 4} >>> setdefault(self, k, d=None): >>> d={1:2,2:4,3:6} >>> d.setdefault(7) >>> d {1: 2, 2: 4, 3: 6, 7: None} >>> update(self, E=None, **F): >>> d={1:2,2:4,3:6} >>> d.update({1:3,5:10}) >>> d {1: 3, 2: 4, 3: 6, 5: 10} >>> values(self): >>> {1:2,2:4,3:6}.keys() dict_keys([1, 2, 3]) >>> {1:2,2:4,3:6}.values() dict_values([2, 4, 6]) >>> {1:2,2:4,3:6}.items() dict_items([(1, 2), (2, 4), (3, 6)]) >>> 可迭代
时间: 2024-10-11 15:17:58