美文网首页
6.python自省

6.python自省

作者: vbuer | 来源:发表于2018-09-03 17:05 被阅读4次

    自省就是面向对象的语言所写的程序在运行时,所能知道对象的类型.简单一句就是运行时能够获得对象的类型.比如type(),dir(),getattr(),hasattr(),isinstance().

    a = [1,2,3]
    b = {'a':1,'b':2,'c':3}
    c = True
    print type(a),type(b),type(c) # <type 'list'> <type 'dict'> <type 'bool'>
    print isinstance(a,list)  # True
    

    相关文章

      网友评论

          本文标题:6.python自省

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