python 中双下划线方法__class__属性

>>> class a(object):
    pass
>>> o=a()
>>> dir(o)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']

>>> o.__class__#对象的类属性指向类对象
<class '__main__.a'>
>>> type(o.__class__)
<type 'type'>
>>> o.__class__.__name__  #a类名字
posted @ 2020-04-02 16:54  hanfe1  阅读(414)  评论(0编辑  收藏  举报