博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python中type和object
阅读量:4361 次
发布时间:2019-06-07

本文共 1044 字,大约阅读时间需要 3 分钟。

type  所有类是type生成的

a = 1b = "abc"print("type a:{}".format(type(a)))print("type int:{}".format(type(int)))print("type b:{}".format(type(b)))print("type str:{}".format(type(str)))result:type a:
type int:
type b:
type str:

在python中是一切皆对象的,类其实也是对象,首先type生成了<class 'int'>这个对象,<class 'int'>又生成了1这个对象,type --> int --> 1

同样,type生成了<class 'str'>这个对象,<class 'type'>又生成了"abc"这个对象,type --> str--> “abc”,即type -->生成类对象 -->对象

 

object   所有类的最顶层基类是object

print("int 的基类是:{}".format(int.__bases__))print("str 的基类是:{}".format(str.__bases__))result:int 的基类是:(
,)str 的基类是:(
,)

<class 'int'>和<class 'str'>的基类都是 <class 'object'>  即:object是最顶层的基类

 

type与object的关系(type的基类是object,object是type生成的,object的基类为空)

print("type 的基类是:{}".format(type.__bases__))print("type object:{}".format(type(object)))print("object 的基类是:{}".format(object.__bases__))result:type 的基类是:(
,)type object:
object 的基类是:()

 

转载于:https://www.cnblogs.com/FG123/p/9463707.html

你可能感兴趣的文章
javascript之,深扒typeof,instanceof操作符
查看>>
18.1 C语言编程集锦
查看>>
node.js安装使用express框架
查看>>
Daily Scrum 1/7/2015
查看>>
leetcode 15.三数之和
查看>>
数据结构(二)栈与队列---栈的应用:四则运算实现
查看>>
自定义Notification实现例子
查看>>
已知空间三个点,解算外接圆圆心坐标,C++编程实现
查看>>
Android上HDMI介绍(基于高通平台)
查看>>
Python 时间复杂度
查看>>
Kubernetes 学习6 Pod控制器应用进阶
查看>>
antd typescript 可编辑单元格
查看>>
二)CodeIgniter源码分析之CodeIgniter.php
查看>>
python---Celery分布式任务队列了解
查看>>
算法习题---栈与队列之栈的数学性质
查看>>
三大主流软件负载均衡器对比(LVS VS Nginx VS Haproxy)
查看>>
Simulation
查看>>
sqli-labs(33)
查看>>
js队列排序
查看>>
Spring 简单配置连接数据库
查看>>