为什么我不能在词典中添加新词?

时间:2014-11-02 12:50:00

标签: error-handling

elif choice == "2":
    print("These are terms stored in the dictionary so far: ")
    for i in values_so_far:
        print(i)
    term = input("\nWhat term do you want me to add?: ")
    if term not in Dictionary:
        definition = input("\nWhat's the definition?: ")
        Dictionary[term] = definition
        print("\n",term,"has been added")
        Dictionary.append[term]
        values_so_far.append[term]
    else:
        print("\nThat term already exists! Try redefining it [option: 3]")

产生错误信息:
追溯(最近的呼叫最后):
      文件“C:\ Users \ Flynn \ Desktop \ programs \ Programming Dictionary.py”,第98行,中         Dictionary.append [长期] AttributeError:'dict'对象没有属性'append'

1 个答案:

答案 0 :(得分:0)

Dictionary[term] = definition已添加了将termdefinition关联到词典的键值对。 append不是为字典定义的方法。

更多关于字典:

Python 2:https://docs.python.org/2/tutorial/datastructures.html#dictionaries

Python 3:https://docs.python.org/3/tutorial/datastructures.html#dictionaries