1. 程式人生 > >python筆記之字典

python筆記之字典

# 定義字典:key-value 形式鍵值對
dic = {"name": "egon"}
print(dic)

#key 可以為那些型別:不可變型別
# value: 可以為哪些型別:所有型別
dic = {1: 1,3.14: 1, True: 1, (): 1, "a": 1}
print(dic)

# 增刪改查
dic = {"name": "egon"}
print(dic)
#增
dic["age"] = 88
print(dic)
# {'name': 'egon', 'age': 88}

#刪
del dic["name"]
print(dic)
# {'age': 88}