python type和object的区别_详解Python中的type和object

type  所有类是type生成的

a = 1

b = "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生成了这个对象,又生成了1这个对象,type --> int --> 1

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

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

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

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

result:

int 的基类是:(,)

str 的基类是:(,)

和的基类都是 即: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 的基类是:()

总结

以上所述是小编给大家介绍的Python中type和object,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!

时间: 2018-08-14

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值