**示例
################字典################
example_dict =
print(example_dict['77'])
#執行結果:88
print(example_dict.get(55))
#執行結果:xx
print(example_dict.get(2222222222))
#執行結果:none
print(example_dict.get(2222222222,'not found'))
#執行結果:not found
#如果不存在會新建,已存在會修改
example_dict['new'] = 'new dict'
print(example_dict)
example_dict['new'] = 'new dict1'
print(example_dict['new'])
#執行結果:
#執行結果:new dict1
################集合################
#集合去重
example_set =
unique_list = list(set(example_set))
print(unique_list)
#執行結果:['a', 1, 2, 3, 'c', 'b']
字典與集合
一 字典 1 字典 於儲存具有對映關係 key value對 資料的集合。2 對於 name 張三 key就是 name key對應的value是 張三 3 乙個key value對 認為是乙個條目 entry 字典是儲存key value對的容器。二 字典類的特點 1 與陣列不同,字典靠key訪問...
字典與集合
一.字典 1 建立字典與呼叫字典 形式字典名稱 dict1 字典的建立 dict2 建立乙個空字典 dict1 k1 v1 2 dict函式的應用 dict1 dict 用dict函式創造乙個空字典 dict2 dict 1,2 2 3 用dict函式建立乙個字典,注意括號的數量,內部既可以用元組,...
字典與集合
day7 emmm5 6待我有空了再補卡 字典是對映型別,列表和元組為序列型別 字典可以有兩種建立方法 1 a 華電 廈大 上交 b 河北 福建 上海 print b a.index 廈大 福建元組的建立用小括號 再利用index查詢 b 中儲存的 對 a 中相應編號的詞的釋義 2 運用dict d...