What is "not in" operator in Python?

PythonServer Side ProgrammingProgramming

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

raja
Published on 11-Feb-2018 23:44:40
Advertisements