Custom Search

Wednesday, November 3, 2010

Python isinstance() check

Python isinstance() check

>>> a = [1]
>>>
>>>
>>> isinstance(a , list)
True

>>> isinstance(a , (list))
True

>>> isinstance(a , tuple)
False

>>> isinstance(a , (tuple))
False

>>> isinstance(a , (tuple, list))
True

>>> isinstance(a , (tuple, list, dict))
True

>>> a = (1)
>>> isinstance(a , (tuple, list, dict))
False

>>> a = (1,)
>>> isinstance(a , (tuple, list, dict))
True

>>> a = {'n':1}
>>> isinstance(a , (tuple, list, dict))
True
>>>



=======================

No comments:

Post a Comment