PEP8 [E713] test for membership should be 'not in'

Eugen picture Eugen · Jul 10, 2014 · Viewed 9k times · Source

Given the following code:

d = {'a':1, 'b':2}

if not 'c' in d:
 print 'kaboom'

if 'c' not in 'd':
 print 'kaboom'

In both cases this prints 'kaboom'. What is the difference and why PEP8 complains about the former.

Answer