Using is, is not, in, and not in Operators in Python List
1) is Operator
The is operator compares the memory address of list, tuple, set, or dictionary objects. If both variables refer to the same object/address, it returns True, otherwise False.
x = [1,2,3]
y = [1,2,3]
if x is y:
print("equall")
else:
print("not equall")
Output:
not equal
2) is not Operator
The is not operator is the opposite of is. It returns True when two variables have different memory addresses.
3) in Operator
The in operator checks whether a value exists in a List, Tuple, Dictionary, or Set.
Example:x = [1,2,3,4,5]
if 21 in x:
print("exist")
else:
print("not exist")
2 Comments
Q:- Implementation of "is" in Pythone Program ?
ReplyDeleteSolution:-
a= ["Computer", "Laptop", "Android", "iPhone","Windows"]
if "Linux" in a:
print("It is Presented in List.")
else:
print("It is Not Presented in List.")
Program of IS operator--->
ReplyDeletey=["Python","Java","C","C++","VB"]
if ".Net" in y:
print("it is there")
else:
print("it is not there")
POST Answer of Questions and ASK to Doubt