type和instance
获取对象类型
type(object)
>>> test_data = [1, 2, 3] >>> type(test_data) <type 'list'> >>>
判断对象是否是已知类型
isinstance(object, class-or-type-or-tuple)
>>> test_data = 123
>>> isinstance(test_data, (int, str))
True
type(object)
>>> test_data = [1, 2, 3] >>> type(test_data) <type 'list'> >>>
isinstance(object, class-or-type-or-tuple)
>>> test_data = 123
>>> isinstance(test_data, (int, str))
True