编程语言
首页 > 编程语言> > 【python日用】python中isinstance()函数

【python日用】python中isinstance()函数

作者:互联网

语法

isinstance(object, classinfo)

函数定义

def isinstance(x, A_tuple): # real signature unknown; restored from __doc__
    """
    Return whether an object is an instance of a class or of a subclass thereof.
    
    A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to
    check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)
    or ...`` etc.
    """
    pass

简单来说呢就是,isinstance() 函数来判断一个对象是否是一个已知的类型,类似 type()。
但是它与type又有区别:

示例

isinstance(2,int)

标签:__,日用,tuple,python,子类,isinstance,type,classinfo
来源: https://blog.csdn.net/weixin_51656605/article/details/112982950