美文网首页python 学习
python isinstance()

python isinstance()

作者: _奔跑的小鱼 | 来源:发表于2019-03-02 20:16 被阅读0次

    Help on built-in function isinstance in module builtins:

    isinstance(obj, class_or_tuple, /)

        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.

    isinstance() 是用来检测一个对象(类的实例)是否属于一个类(class)或者其子类:

    isinstance(7, int)

    Out[1]: True

    这里要注意:

    isinstance(object, type)  # 当object作为一个对象的时候

    Out[1]: True

    isinstance(type, object)  # 当type作为一个对象的时候

    Out[2]: True

    相关文章

      网友评论

        本文标题:python isinstance()

        本文链接:https://www.haomeiwen.com/subject/ftpyuqtx.html