Python:type、object、class

Python: 一切为对象

>>> a = 1

>>> type(a)

>>> type(int)

type => int => 1

type => class => obj

type是个类,生成的类也是对象,生成的实例是对象

>>>class Student:

>>> pass

>>>

>>>stu = Student()

>>>type(stu)

__main__.Student

>>>Student.__base__

object

Student的基类是obj

>>>class MyStudent(Student):

>>> pass

>>>

>>>MyStudent.__base__

__main__.Student

MyStudent继承Student

MyStudent的基类是Student

object是最顶层的基类

type是个类,同时type也是个对象

>>> type.__base__

object

>>> type(object)

type

>>> object.__bases__

()

object是type的实例

type继承object

我们可以把这些分为3类:

第一类:type自成一类,type是自己的对象(可以实例化自己),type可以把所有变成他的对象

第二类:list、str、Student…类会继承object,list、str、Student…是类,同时也是type的对象。object是所有的基类(一切都继承object)

第三类:生成的对象

Python 内置类型

对象的三个特征:

身份

类型

身份:每个对象身份均不同

>>> a = 1

>>> id(a)

4333971504

>>> a = {}

>>>id(a)

4393125064

类型

None(全局只有一个)

数值

int

float

complex(复数)

bool

迭代类型

序列类型

list

bytes、bytearray、memoryview(二进制序列)

range

tuple

str

array

映射(dict)

集合

set

frozenset

上下文管理类型(with)

其他

模块类型

class和实例

函数类型

方法类型

代码类型

object对象

type类型

ellipsis类型

notimplemented类对象

None类型:Python在程序启动的时候会生成一个None对象

>>> a = None

>>> b = None

>>> id(a) == id(b)

True

以上这篇Python:type、object、class与内置类型实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

object的实例是 python_Python:type、object、class与内置类型实例相关推荐

  1. 什么是实例对象python_python判断类型:想知道一个对象(实例或者变量)是什么类型,什么结构的...

    用type和isinstance 例子: ta={} ta['1']="a" ta={'2':"b"} ta['3']="c" #使用两个函 ...

  2. 设计模式之美:Type Object(类型对象)

    索引 意图 结构 参与者 适用性 效果 相关模式 实现 实现方式(一):Type Object 的经典介绍. 实现方式(二):Type Object 在游戏设计中的使用. 意图 允许在运行时动态灵活的 ...

  3. 关于AttributeError: type object ‘XXX‘ has no attribute ‘XXX‘的问题

    关于AttributeError: type object 'XXXXXX' has no attribute 'name'的报错的原因,先运行运行一段代码 例如: class Person(obje ...

  4. python object has no attribute_如何修复python中的“AttributeError:type object has no attribute”?...

    您的代码引发此异常: AttributeError: type object 'Meeting' has no attribute 'datetime' 在这一行: meeting_start = M ...

  5. Oracle 自定义类型TYPE(subtype, type object, type body, type table) 用法

    原 ORACLE 自定义类型 type/ object 2017年03月28日 13:58:23 tan1012194073 阅读数:5999 版权声明:本文为博主原创文章,未经博主允许不得转载. h ...

  6. python 报错 AttributeError: type object ‘datetime.datetime‘ has no attribute ‘datetime‘

    python报错:type object 'datetime.datetime' has no attribute 'datetime' 描述:在第一个python程序里还未报错,第二个程序完全复制过 ...

  7. 成功解决type object ‘h5py.h5.H5PYConfig‘ has no attribute ‘__reduce_cython__‘

    成功解决type object 'h5py.h5.H5PYConfig' has no attribute '__reduce_cython__' 目录 解决问题 解决思路 解决方法 第一步,cond ...

  8. 成功解决AttributeError: type object 'scipy.interpolate.interpnd.array' has no attribute '__reduce_cython

    成功解决AttributeError: type object 'scipy.interpolate.interpnd.array' has no attribute '__reduce_cython ...

  9. 成功解决AttributeError: type object ‘h5py.h5r.Reference‘ has no attribute ‘__reduce_cython__‘

    成功解决AttributeError: type object 'h5py.h5r.Reference' has no attribute '__reduce_cython__' 目录 解决问题 解决 ...

最新文章

  1. java 数据结构容器之HashSet
  2. shell__常用命令__awk
  3. 判断一个字符串是否全部相同
  4. 搜索引擎设计实用教程(2)-以百度为例
  5. [Abp vNext 源码分析] - 1. 框架启动流程分析
  6. 【Linux学习】强大的文本分析工具AWK
  7. Java各进制之间的转换
  8. java溢出怎么处理_java数据溢出怎么处理?
  9. springboot中service层注入的是实现类,但Controller层接收的是接口
  10. linux开发板显示百叶窗图片,03Linux命令操作2
  11. Mac安装CentOS7
  12. Two Strings(CF-223B)
  13. 【POJ2406】Power Strings(KMP)
  14. C++算法之遗传算法及实现
  15. QtSQL的使用心得
  16. vb.net设置分辨率和缩放比例_配置高不一定性能强,Win 10做好这些设置才能“6到飞起”!...
  17. Java操作excel锁定
  18. 如何给图片降噪?看完你就学会了
  19. Python读取docx表格中的合并单元格信息
  20. 客户端解析html5,基于HTML5的WebGIS实时客户端设计

热门文章

  1. Ubuntu 12.04 图形界面问题解决 开机死机
  2. 内存版u-boot制作
  3. 不同场景下MySQL的迁移方案
  4. 金山云html文件,金山云安全开放平台
  5. mac安装完mysql后关机特别慢_解决Mac升级到10.12后关机很慢的问题
  6. P1080 国王游戏(贪心+高精度乘除及大数比较)
  7. 蚂蚁动态卡片,让App首页实现敏捷更新
  8. 应云而生,幽灵的威胁 - 云原生应用交付与运维
  9. 【计算机视觉】究竟谁能解决可解释性 AI?
  10. AliGraph:一个工业级的图神经网络平台