【Python】-- 字典

來源:互聯網
上載者:User

標籤:刪除   name   hat   upd   沒有   items   通過   位置   根據   

 

#【字典】    #映射    #字典是無序儲存的,沒有位置關係    print(id(a))   #列印a的記憶體位址    #不可變類型:整型,字串,元組    #可變類型:列表,字典     dictionary = {‘name‘:‘zhangw‘,‘age‘:35,‘isboy‘:True,}    dictionary2 = {‘name‘:‘haha‘,‘what‘:‘qie‘}    #字典可以做值,不能做鍵  #字典名{鍵:值,鍵:值}  #字典兩大特點            #無序    #鍵唯一    #增加    dictionary[‘name‘] = 18    dictionary[‘haha‘] = ‘建立‘    ret=dictionary.setdefault(‘age‘,32)#鍵存在,不改動,返回字典中相對應的值,鍵不存在,在字典裡增加新的索引值對,並返回相應的值    #尋找        #通過鍵        print(dictionary[‘name‘])        print(dictionary.keys()) #尋找鍵            #尋找出來的是dict_key類型        print(dictionary.values())        print(dictionary.items())     #修改        dictionary.update(dictionary2)    #刪除        del dictionary[‘name‘] #根據鍵刪除        dictionary.clear() #清空字典        del.dictionary #刪除整個字典  #排序           sorted(dictionary)

【Python】-- 字典

聯繫我們

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