What are the differences between these two code fragments?
Using type():
type()
import types if type(a) is types.DictType: do_something(
According to python documentation here is a statement:
8.15. types — Names for built-in types Starting in Python 2.2, built-in factory functions such as int() and str() are also names for the corresponding types.
Starting in Python 2.2, built-in factory functions such as int() and str() are also names for the corresponding types.
int()
str()
So isinstance() should be preferred over type().