使用字典构建地址簿

时间:2016-11-30 04:22:28

标签: python

我正在制作一个tkinter通讯录程序。我正在研究使用词典来构建通讯录程序。如何在字典中输入名称和地址信息?有人能指出我正确的方向。

TIA,

加布里埃尔

1 个答案:

答案 0 :(得分:0)

回答我所看到的唯一问题:

如何在字典中输入姓名和地址信息???

借用python documentation字典:

>>> AddressDictionary = {'jack': "Jack's Address", 'jane': "Jane's Address"} # Create dictionary with some names and addresses
>>> AddressDictionary['John'] = "John's Address" # Add new address for John
>>> AddressDictionary
{'jane': "Jane's Address", 'John': "John's Address", 'jack': "Jack's Address"}
>>> AddressDictionary['jack'] # Fetch Jack's address
"Jack's Address"
>>> del AddressDictionary['jack'] # Delete jack and his address from the dictionary
>>> AddressDictionary['Harry'] = "Harry's Address" # Add Harry and his address
>>> AddressDictionary
{'jane': "Jane's Address", 'John': "John's Address", 'Harry': "Harry's Address"}
>>> AddressDictionary.keys() # Fetch all the names (keys) in your address dictionary
['jane', 'John', 'Harry']
>>> 'John' in AddressDictionary  # Do you have John in your address book
True