isinstance will also return True if obj is a sublcass of tuble or list. It is usually considered safer to use isinstance unless you know for sure that the type will be a tuple or list and not a sublcass of those.
what benefit does isinstance give over type()? I'm not arguing, I'm asking.
Personally I think:
if isinstance(obj, (tuple,list)):
is more confusing (especially for newcomers) than:
if type(obj) in (types.ListType, types.TupleType):
Comment
isinstance will also return True if obj is a sublcass of tuble or list. It is usually considered safer to use isinstance unless you know for sure that the type will be a tuple or list and not a sublcass of those.
Parent comment
what benefit does isinstance give over type()? I'm not arguing, I'm asking. Personally I think: if isinstance(obj, (tuple,list)): is more confusing (especially for newcomers) than: if type(obj) in (types.ListType, types.TupleType):
Replies
That is very useful to know! Thank you.