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

 

posted @ 2014-09-09 23:32  周文洪  阅读(185)  评论(0编辑  收藏  举报