On Feb 8, 5:09 pm, c james <[EMAIL PROTECTED]> wrote: > Try this > > >>> sample = {'t':True, 'f':False} > >>> 't' in sample > True > >>> type('t' in sample) > <type 'bool'> > >>> 't' in sample == True > > False > > Why is this? Now try>>> bool('t' in sample) == True > > True > > Can someone explain what is going on?
This is because in Python '==' and 'in' are comparison operators and in Python you can chain comparisons. Typical usage is: if 3 <= x < 9: # meaning (3 <= x) and (x < 9) # do something... So 't' in sample == True means the same as ('t' in sample) and (sample == True) Which will never be true as sample is a dictionary. To solve this, use brackets: >>> ('t' in sample) == True True HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list