Checking if a word is in a list in Python

Checking if a word is in a list in Python

I would suggest a function along the following:

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

This is assuming youre using Python 3.x, if youre using Python 2, then there shouldnt be parenthesis in your print statements

Hope this helps!

Welcome to Python! This sort of thing is really elementary here. What you need is

print(deer in myMammals)
>> True

Checking if a word is in a list in Python

Leave a Reply

Your email address will not be published. Required fields are marked *