5 1 字典操作

2021-10-03 05:08:20 字數 1176 閱讀 8264

字典操作

第二週-第12章節-python3.5-字典的使用

增刪改查功能,35分鐘,迴圈?

字典**目錄

data = , "

朝陽":, "

東直門":, },

"海淀":{}, },

'山東':, "

青島":{}, "

濟南":{} },

'廣東':, "

常熟":{}, "

佛山":{}, },

}exit_flag = false

while not exit_flag:

for i in data:

print(i)

choice = input("

選擇進入

1>>:")

if choice in data:

while not exit_flag:

for i2 in data[choice]:

print("\t",i2)

choice2 = input("

選擇進入

2>>:")

if choice2 in data[choice]:

while not exit_flag:

for i3 in data[choice][choice2]:

print("\t\t", i3)

choice3 = input("

選擇進入

3>>:")

if choice3 in data[choice][choice2]:

for i4 in data[choice][choice2][choice3]:

print("\t\t",i4)

choice4 = input("

最後一層,按b返回

>>:")

if choice4 == "b":

pass

elif choice4 == "q":

exit_flag = true

if choice3 == "b":

break

elif choice3 == "q":

exit_flag = true

if choice2 == "b":

break

elif choice2 == "q":

exit_flag = true

60 字典刪除操作

增加 改 查 key 刪除 刪除 del dict key 內建函式 dict.pop key popitem dict1 del dict1 alias print dict1 刪除乙個不存在的key keyerror haha pop dict1.pop tom print dict1 prin...

python3 字典操作

dictionary 字典 裝下整個世界 字典是python中的唯一的對映型別,採用鍵值對的形式儲存資料 key value python對key進行雜湊函式運算,根據計算結果決定value儲存的位址,所以字典是無序儲存的,且key必須是可雜湊的。可雜湊表示key必須是不可變型別,如 數字 字串 元...

Python3 字典操作

usr bin python coding utf 8 author zhaosj python 基礎字典 python的字典資料結構與現實中的字典類似,以鍵值對 key value 的形式表現出來 user info 注意 插入mongodb資料庫需要用字典資料結構 字典是另一種可變容器模型,且可...