http://legacy.python.org/dev/peps/pep-0008/
Object type comparisons should always use isinstance() instead of comparing types directly.
Yes: if isinstance(obj, int): No: if type(obj) is type(1):
When checking if an object is a string, keep in mind that it might be a unicode string too! In Python 2, str and unicode have a common base class, basestring, so you can do:
if isinstance(obj, basestring):
Note that in Python 3, unicode and basestring no longer exist (there is only str) and a bytes object is no longer a kind of string (it is a sequence of integers instead)