What is the best way to check whether a given object is of a given type? How about checking whether the object inherits from a given type?
Let\'s say I have an objec
isinstance(o, str) will return True if o is an str or is of a type that inherits from str.
isinstance(o, str)
True
o
str
type(o) is str will return True if and only if o is a str. It will return False if o is of a type that inherits from str.
type(o) is str
False