Skip to content
Advertisement

which is better to use ( a not in b) or (not a in b ) in python? [closed]

I am an intermediate in python programming but I faced this in python condition,

a not in b and not a in b

for example

item_list = [1,2,3,4,5]
if 6 not in  item_list:
    print('6 not found')

elif not 9 in item_list:
    print('9 not found')

The all codes above give me the same results is there any difference from view of performance or bugs.

Advertisement

Answer

is not in isn’t valid Python syntax. Contrary to your claims, it doesn’t work.

not in is the right way of doing it.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement