لَآ إِلَـٰهَ إِلَّا هُوَ
LA ILAHA ILLA HU
Allah, Your Lord There Is No Deity Except Him.

Lesson 16 A: Membership Operators In Python

Membership Operators In Python are used to test if a sequence is presented in an object.

Membership Operator: in

Example 1.

Output: Returns True if a sequence with the specified value is present in the object.

x in y

Illustration

Code

x = ["pineapple", "banana"]

print("banana" in x)

Output: Returns True because a sequence with the value "banana" is in the list.

Membership Operator: not in

Example 2.

Output: Returns True if a sequence with the specified value is not present in the object.

x not in y

Illustration

Code

x = ["pineapple", "banana"]

print("apple" not in x)

returns True because a sequence with the value "apple" is not in the list