且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查一个单词是否在 Python 的列表中

更新时间:2022-04-14 06:28:41

我建议使用以下功能:

def check(word, list):
    if word in list:
        print("The word is in the list!")
    else:
        print("The word is not in the list!")

这里假设您使用的是 Python 3.x,如果您使用的是 Python 2,那么您的打印语句中不应有括号

This is assuming you're using Python 3.x, if you're using Python 2, then there shouldn't be parenthesis in your print statements

希望这会有所帮助!