python字典類型的底層如何實現(xiàn)

這篇文章給大家分享的是有關(guān)python字典類型的底層如何實現(xiàn)的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

在洞口等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站建設(shè)、成都網(wǎng)站制作 網(wǎng)站設(shè)計制作按需制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計,成都營銷網(wǎng)站建設(shè),外貿(mào)營銷網(wǎng)站建設(shè),洞口網(wǎng)站建設(shè)費用合理。

1、字典類型的底層基于哈希表。

2、字典中鍵的數(shù)據(jù)類型必須是靜態(tài)數(shù)據(jù)類型,如簡單的數(shù)據(jù)類型、字符串和元組。字典類型是基于哈希表的數(shù)據(jù)結(jié)構(gòu)。

實例

# -*- coding: utf-8 -*-
"""
@Time    : 2021/8/14 21:04
@Author  : LYP
@FileName: dic_Python.py
@SoftWare: PyCharm
"""
dict2 = { 'abc': 123, 98.6: 37 }
scores = {'數(shù)學(xué)': 95, '英語': 92, '語文': 84, '化學(xué)':90 , '生物':91 , '物理':80}
dic={}
dic[1]='hello'
dic[2]='world'
#print(dic)
 
# print(dict2)
#
# print(scores)
print("scores['數(shù)學(xué)']:",scores['數(shù)學(xué)'])
print("scores['英語']:",scores['英語'])
print("scores['化學(xué)']:",scores.get('化學(xué)'))
print("scores['生物']:",scores.get('生物'))
 
print(scores)
for key,value in scores.items():
    print(key,"----->",value)
 
print("向字典中添加數(shù)值")
 
scores['歷史']=80
print(scores)
 
scores.setdefault('地理',89)
print(scores)
print("刪除元素")
del scores['地理']
print(scores)
scores.pop('歷史')
print(scores)
 
#scores.clear()
#print(scores)
print("修改值")
print(scores)
scores['數(shù)學(xué)']=100
print(scores)
 
print("判斷字典中是否包含某個鍵值對")
print("scores中是否包括數(shù)學(xué)",'數(shù)學(xué)' in scores)
print("scores中是否包括地理",'地理' in scores)
print("scores中是否包括歷史",'歷史' not in scores)
 
print(scores.keys())
print(scores.values())
print(scores.items())

感謝各位的閱讀!關(guān)于“python字典類型的底層如何實現(xiàn)”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

網(wǎng)頁標(biāo)題:python字典類型的底層如何實現(xiàn)
網(wǎng)頁地址:http://muchs.cn/article38/gheopp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、外貿(mào)建站、定制網(wǎng)站、品牌網(wǎng)站設(shè)計企業(yè)網(wǎng)站制作、定制開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)