object的实例是 python_Python:type、object、class与内置类型实例
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与内置类型实例相关推荐
- 什么是实例对象python_python判断类型:想知道一个对象(实例或者变量)是什么类型,什么结构的...
用type和isinstance 例子: ta={} ta['1']="a" ta={'2':"b"} ta['3']="c" #使用两个函 ...
- 设计模式之美:Type Object(类型对象)
索引 意图 结构 参与者 适用性 效果 相关模式 实现 实现方式(一):Type Object 的经典介绍. 实现方式(二):Type Object 在游戏设计中的使用. 意图 允许在运行时动态灵活的 ...
- 关于AttributeError: type object ‘XXX‘ has no attribute ‘XXX‘的问题
关于AttributeError: type object 'XXXXXX' has no attribute 'name'的报错的原因,先运行运行一段代码 例如: class Person(obje ...
- python object has no attribute_如何修复python中的“AttributeError:type object has no attribute”?...
您的代码引发此异常: AttributeError: type object 'Meeting' has no attribute 'datetime' 在这一行: meeting_start = M ...
- Oracle 自定义类型TYPE(subtype, type object, type body, type table) 用法
原 ORACLE 自定义类型 type/ object 2017年03月28日 13:58:23 tan1012194073 阅读数:5999 版权声明:本文为博主原创文章,未经博主允许不得转载. h ...
- python 报错 AttributeError: type object ‘datetime.datetime‘ has no attribute ‘datetime‘
python报错:type object 'datetime.datetime' has no attribute 'datetime' 描述:在第一个python程序里还未报错,第二个程序完全复制过 ...
- 成功解决type object ‘h5py.h5.H5PYConfig‘ has no attribute ‘__reduce_cython__‘
成功解决type object 'h5py.h5.H5PYConfig' has no attribute '__reduce_cython__' 目录 解决问题 解决思路 解决方法 第一步,cond ...
- 成功解决AttributeError: type object 'scipy.interpolate.interpnd.array' has no attribute '__reduce_cython
成功解决AttributeError: type object 'scipy.interpolate.interpnd.array' has no attribute '__reduce_cython ...
- 成功解决AttributeError: type object ‘h5py.h5r.Reference‘ has no attribute ‘__reduce_cython__‘
成功解决AttributeError: type object 'h5py.h5r.Reference' has no attribute '__reduce_cython__' 目录 解决问题 解决 ...
最新文章
- java 数据结构容器之HashSet
- shell__常用命令__awk
- 判断一个字符串是否全部相同
- 搜索引擎设计实用教程(2)-以百度为例
- [Abp vNext 源码分析] - 1. 框架启动流程分析
- 【Linux学习】强大的文本分析工具AWK
- Java各进制之间的转换
- java溢出怎么处理_java数据溢出怎么处理?
- springboot中service层注入的是实现类,但Controller层接收的是接口
- linux开发板显示百叶窗图片,03Linux命令操作2
- Mac安装CentOS7
- Two Strings(CF-223B)
- 【POJ2406】Power Strings(KMP)
- C++算法之遗传算法及实现
- QtSQL的使用心得
- vb.net设置分辨率和缩放比例_配置高不一定性能强,Win 10做好这些设置才能“6到飞起”!...
- Java操作excel锁定
- 如何给图片降噪?看完你就学会了
- Python读取docx表格中的合并单元格信息
- 客户端解析html5,基于HTML5的WebGIS实时客户端设计