Skip to content

Python not in operator

  • by

Python not in operator evaluates to true if it does not finds a variable in the specified sequence and false otherwise. It works exactly the opposite way as the in operator works.

Python not in operator

A simple example code checks the presence of a specified value inside a given sequence (list, string, tuple) but its return values are totally opposite to that of the in operator.

list1 = [1, 2, 3, 4, 5]
print(5 not in list1)  # False

s = "A is A"
print("is" not in s)  # False

tuple1 = (11, 22, 33, 44)
print(88 not in tuple1)  # True


Python not in operator

not in operator working on Dictionary

dict1 = {1: "one", 2: "two", 3: "three", 4: "four"}

print("one" not in dict1)

print(3 not in dict1)

print(5 not in dict1)

Do comment if you have any doubts or suggestions on this Python operator topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

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