python的class(类)中的object是什么意思?

https://blog.csdn.net/DeepOscar/article/details/80947155
Person类很明显能够看出区别,不继承object对象,只拥有了__doc__ , module 和 自己定义的name变量, 也就是说这个类的命名空间只有三个对象可以操作.

Animal类继承了object对象,拥有了好多可操作对象,这些都是类中的高级特性。

对于不太了解python类的同学来说,这些高级特性基本上没用处,但是对于那些要着手写框架或者写大型项目的高手来说,这些特性就比较有用了,比如说tornado里面的异常捕获时就有用到__class__来定位类的名称,还有高度灵活传参数的时候用到__dict__来完成.

最后需要说清楚的一点, 本文是基于python 2.7.10版本,实际上在python 3 中已经默认就帮你加载了object了(即便你没有写上object)。

这里附上一个表格用于区分python 2.x 和 python 3.x 中编写一个class的时候带上object和不带上object的区别.

python 2.x python 2.x python 3.x python 3.x
不含object 含object 不含object 含object
doc doc doc doc
module module module module
say_hello say_hello say_hello say_hello
class class class
delattr delattr delattr
dict dict dict
format format format
getattribute getattribute getattribute
hash hash hash
init init init
new new new
reduce reduce reduce
reduce_ex reduce_ex reduce_ex
repr repr repr
setattr setattr setattr
sizeof sizeof sizeof
str str str
subclasshook subclasshook subclasshook
weakref weakref weakref
dir dir
eq eq
ge ge
gt gt
le le
lt lt
ne ne
————————————————

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值