python dict操作,pythondict

來源:互聯網
上載者:User

python dict操作,pythondict

 1 d1 = {'one': 1, 'two': 2} 2 d2 = {'one': 1, 'two': 2} 3 d3 = {'one': 1, 'two': 2} 4 print(dir(d1)) 5  6 # 1、contians 7 print('one' in d1) 8  9 # 2、eq10 print(d1 == d2)11 12 # 3、len13 print(len(d1))14 15 # 4、ne16 print(d1 != d2)17 18 # 5、iter19 print(iter(d1))20 21 # 6、clear22 d3.clear()23 print(d3)24 25 # 7、copy26 d4 = d1.copy()27 print(d4)28 29 # 8、fromkeys30 l = [1, 2, 3]31 d5 = dict.fromkeys(l, 'w')32 print(d5)33 34 # 9、get35 print(d1.get('one'))36 print(d1.get('three', 3))37 38 # 10、items39 print(d1.items())40 41 # 11、keys42 print(d1.keys())43 44 # 12、pop45 d = d1.pop('three', 3)46 print(d)47 print(d1)48 d = d1.pop('one')49 print(d)50 print(d1)51 52 # 13、popitem53 d = d2.popitem()54 print(d)55 print(d2)56 57 # 14、setdefault58 d = d2.setdefault('one')59 print(d)60 print(d2)61 d = d2.setdefault('three', 3)62 print(d)63 print(d2)64 65 # 15、update66 d1.update({'three': 3})67 print(d1)68 69 # 16、values70 print(d1.values())

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.