zoukankan      html  css  js  c++  java
  • isinstance

    If realize this funciton by C language:

    if (typeof(objA) == typeof(String))
    {
    //TODO
    }

    In Python: 

    class objA:
    pass

    A
    = objA()
    B
    = 'a','v'
    C
    = 'a string'

    print isinstance(A, objA)
    print isinstance(B, tuple)
    print isinstance(C, basestring)

    The example code is come from coderzh's blog, thank you very much!

    isinstance(object, classinfo)

    Return true if the object argument is an instance of the classinfo argument, or of a (direct or indirect) subclass thereof. Also return true if classinfo is a type object (new-style class) and object is an object of that type or of a (direct or indirect) subclass thereof. If object is not a class instance or an object of the given type, the function always returns false. If classinfo is neither a class object nor a type object, it may be a tuple of class or type objects, or may recursively contain other such tuples (other sequence types are not accepted). If classinfo is not a class, type, or tuple of classes, types, and such tuples, a TypeError exception is raised.

  • 相关阅读:
    离线安装MariaDB 10.4.13
    YUM 的使用
    Crontab 定时任务
    静默安装卸载 ORACLE
    java 改变图片的DPI
    Java TIF、JPG、PNG等图片转换
    key可重复的Map
    集合对象去重
    Java创建TXT文件并写入 内容
    Java已知图片路径下载图片到本地
  • 原文地址:https://www.cnblogs.com/allenblogs/p/1762820.html
Copyright © 2011-2022 走看看