Hot For Coding
Python isinstance()判断对象类型

在Python中可以使用type()isinstance()这两个函数判断对象类型,而isinstance函数的使用上比type更加方便。

例子

# coding=utf-8
 
a = 10
 
def b():
  pass
 
print isinstance(a, (int, str))
print isinstance(a, (float, str))
print isinstance(b, (str, int))
 
class c:
  pass
 
obj = c()
 
print isinstance(obj, (c, int))

Output:

True
False
False
True

TITLE: Python isinstance()判断对象类型

LINK: https://www.qttc.net/269_python_isinstance.html

NOTE: 转载内容请注明出处