python3字典方法

來源:互聯網
上載者:User

標籤:subclass   rom   複製   rgs   type   清除   set   ict   索引值   

>>> 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)])>>>可迭代

 

python3字典方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.