Membership Operators


Membership Operators

🙋 Need help? Ask an expert now!

The in operator

Membership operators are used to test if a sequence is presented in an object:

Here are some examples of how you can use the in operator along with the not operator

# Declare the list lst = [1,2,3,4] print('Is 4 in the list? ', 4 in lst) # Returns True print('Is 5 in the list? ',5 in lst) # Return False #Declare the string string = 'Cats are cool and cuddly' print('Is the word Cats in the string? ', 'Cats' in string) print('Are the words Hellow World in the string? ','Hello World' not in string)
Edit Me on GitHub!