Python使用内置函数type创建新类型-创新互联

这篇文章将为大家详细讲解有关Python使用内置函数type创建新类型,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

专注于为中小企业提供成都网站建设、成都做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业大同免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

英文文档:

class type(object)

class type(name, bases, dict)

With one argument, return the type of an object. The return value is a type object and generally the same object as returned by object.__class__.

The isinstance() built-in function is recommended for testing the type of an object, because it takes subclasses into account.

With three arguments, return a new type object. This is essentially a dynamic form of the class statement. The namestring 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 is copied to a standard dictionary to become the __dict__ attribute.

  返回对象的类型,或者根据传入的参数创建一个新的类型

说明:

  1. 函数只传入一个参数时,返回参数对象的类型。 返回值是一个类型对象,通常与对象.__ class__返回的对象相同。

#定义类型A
>>> class A:
  name = 'defined in A'

#创建类型A实例a
>>> a = A()

#a.__class__属性
>>> a.__class__


#type(a)返回a的类型
>>> type(a)


#测试类型
>>> type(a) == A
True

网站标题:Python使用内置函数type创建新类型-创新互联
文章路径:http://bzwzjz.com/article/dihijj.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 四川成都网站建设 H5网站制作 网站制作公司 成都网站建设 网站建设改版 成都网站建设公司 成都网站建设 LED网站设计方案 温江网站设计 移动手机网站制作 成都品牌网站设计 成都网站设计公司 高端网站设计 泸州网站建设 成都网站建设公司 重庆网站建设 成都网站制作 定制网站设计 古蔺网站建设 外贸网站建设 营销网站建设 做网站设计