Python编程常用技巧,你全知道么?(17)

>>> type(None)

<class 'NoneType'>

>>> type(abs)

<class 'builtin_function_or_method'>

对类对象type()返回的是对应class类型 。 下面是判断两个变量的type类型是否相同:

>>> type(11) == type(22)

True

>>> type('abc') == str

True

>>> type('abc') == type(33)

False

isinstance():可以显示对象是否是某种类型

>>> class Husty(Dog):

... pass

...

>>> a = Animal()

推荐阅读