emptyDict1 = dict()
empryDict2 = {}
iniDict = {'name': Saxon, 'GPA': 4.00, 'Age': 18}
iniDict = {'name': 'Saxon', 'GPA': 4.00, 'Age': 18}
print(iniDict['name']) # Saxon
print(iniDict['GPA']) # 4.0
print(iniDict['Age']) # 18
modifyDict = {'name': 'Saxon', 'Age': 19}
modifyDict['Age'] = 18
print(modifyDict['Age']) # 18
deleteDict = {'name': 'Saxon', 'Age': 19, 'Love': True}
del deleteDict['Love']
print(deleteDict) # {'name': 'Saxon', 'Age': 19}
funcDict = {'a': 1, 'b': 2, 'c': 3}
' len(): key-value 數目 '
print(len(funcDict)) # 3
' list(): 以列表形式輸出所有的key '
print(list(funcDict)) # ['a', 'b', 'c']
' str(): 輸出字典可列印的字串(官方說的是適合人閱讀的形式) '
print(str(funcDict)) # {'a': 1, 'b': 2, 'c': 3}
6.1 dict.items(): a set-like object providing a view on dict’s items
返回 dict 中所有的鍵值對
type @return: dict
methodDict = {'Name': 'Saxon', 'Gender': 'Male', 'Age': 19}
item = list(methodDict.items())
print(item) # [('Name', 'Saxon'), ('Gender', 'Male'), ('Age', 19)]