What is "not in" operator in Python?


In Python, 'not in' membership operator evaluates to true if it does not finds a variable in the specified sequence and false otherwise. For example

>>> a = 10
>>> b = 4
>>> l1 = [1,2,3,4,5]
>>> a not in l1
True
>>> b not in l1
False

Since 'a' doesn't belong to l1, a not in b returns True. However, b can be found in l1, hence b not in l1 returns False

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements