python之类的属性

class type(object)

With one argument, return the type of an object. The return value is a type object. The isinstance() built-in function is recommended for testing the type of an object.

意思是当传递的参数个数为1时,返回的是这个对象的类型

class type(name, bases, dict)

With three arguments, return a new type object. This is essentially a dynamic form of the class statement. The name string is the class name and becomes the __name__ attribute; the bases tuple itemizes the base classes and becomes the __bases__ attribute; and the dict dictionary is the namespace containing definitions for class body and becomes the __dict__ attribute. For example, the following two statements create identical type objects:

当传参是三个的时候,返回的是一个新类型的对象。这个本质是动态声明类的一种形式,包括类的名字由名字属性,基础类属性,以及一个字典目录包含这个类的定义。

>>> class X(object):
... a = 1
...
>>> X = type('X', (object,), dict(a=1))

>>> X.__dict__
dict_proxy({'a': 1, '__dict__': <attribute '__dict__' of 'X' objects>, '__module__': '__main__', '__weakref__': <attribute '__weakref__' of 'X' objects>, '__doc__': None})

上一篇:web.xml文件详解


下一篇:全网最详细的Windows里下载与安装Sublime Text *(图文详解)