美文网首页
Python自省

Python自省

作者: 无敌的肉包 | 来源:发表于2018-03-30 17:49 被阅读0次

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

    #Example
    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
    

    相关文章

      网友评论

          本文标题:Python自省

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