Python. AttributeError: 'str' object has no attribute for the words

Python. AttributeError: 'str' object has no attribute for the words

GREETING_KEYWORDS = ("hello", "hi", "greetings", "sup", "whats up",)
GREETING_RESPONSES = ["sup bro", "hey", "*nods*", "hey you get my snap?"]
def check_for_greeting(sentence):
    for word in sentence.words:
        if word.lower() in GREETING_KEYWORDS:
             return random.choice(GREETING_RESPONSES)
user= input(">>> ")
check_for_greeting(user)

AttributeError: 'str' object has no attribute 'words'. sentence.words is not proper. How to get the GREETING_RESPONSES if user is giving input in GREETING_KEYWORDS. I am using python 3.5

变量sentence是一个字符串。我知道 的意图 是一个句子,里面有单词,但是 Python 就只是一个字符串,里面有字符。 sentence 只包含 "words" 是因为你打算 " " 是一个特殊字符,它将字符串中的字符分成单词。你必须告诉 Python 这个意图。使用 split() 方法来做到这一点:

def check_for_greeting(sentence):
    words = sentence.split()
    for word in words:
        if word.lower() in GREETING_KEYWORDS: