.lower 不适用于我在 pycharm 中的代码

.lower is not working for my code in pycharm

我是 python 的新手,这是我的代码,.lower 通常可以工作,但这次不行。

technical_dict = {
        dict : 'stores a key/value pair',
        list : 'stores a value at each index',
        map : 'see dict',
        set : 'stores unordered unique elements'
    }

    userInput = (input("What term would you like to lookup or type 'exit' to stop:"))
    if userInput.lower() not in technical_dict:
        print("Term does not exist in technical dictionary")
    if userInput.lower()  in technical_dict:
        print(technical_dict[userInput.lower()])
        while userInput.lower() != "exit":
            userInput = input("What term would you like to lookup or type 'exit' to stop:")
            if userInput.lower() in technical_dict:
        print(technical_dict[userInput.lower()])
            if userInput.lower() not in technical_dict:
                print("Term does not exist in technical dictionary")
                break

您创建词典的方式似乎有问题。您现在拥有的键值不是字符串类型或 str。这就是为什么您收到字典没有属性 'lower' 的错误。要修复它,您可以更改值,使它们的类型为字符串。试试这个:

technical_dict = {
        'dict' : 'stores a key/value pair',
        'list' : 'stores a value at each index',
        'map' : 'see dict',
        'set' : 'stores unordered unique elements'
    }