zoukankan      html  css  js  c++  java
  • 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})

  • 相关阅读:
    程序写法
    2011年C++再次给力
    WIN7+LINUX双系统
    随机洗牌算法
    Eclipse快捷键大全
    Android 编程规范
    android Context 上下文的几点解析
    消息模式Toast.makeText的几种常见用法
    Eclipse的优化
    用PULL解析器解析XML文件
  • 原文地址:https://www.cnblogs.com/passion-hzhang/p/5992053.html
Copyright © 2011-2022 走看看