Ref: [1] - Stackoverflow - What's the canonical way to check for type in python?
Exact type
if type(o) is str:
print "this is a string"
Instance of type or instance of the subclass
if isinstance(o, str):
print "this is a string or a instance of subclass of string"
There are more patterns in the reference to deal with more complex usecases.
Recommended Posts