python中object是什么_Python中Class中的object是什么意思?

Python2.2之前的版本使用旧风格类,存在一些限制,如不能直接继承内置类型。为解决此问题,Python引入了新风格类,但为了保持向后兼容,创建了object类作为所有新风格类的基类。在Python2.X中,不指定父类的class声明将创建旧风格类,而指定object为父类则创建新风格类。建议通常使用新风格类,因为某些特性(如@property装饰器)不适用于旧风格类。
摘要由CSDN通过智能技术生成

In short, it sets free magical ponies.

In long, Python 2.2 and earlier used "old style classes". They were a particular implementation of classes, and they had a few limitations (for example, you couldn't subclass builtin types). The fix for this was to create a new style of class. But, doing this would involve some backwards-incompatible changes. So, to make sure that code which is written for old style classes will still work, the object class was created to act as a superclass for all new-style classes. So, in Python 2.X, class Foo: pass will create an old-style class and class Foo(object): pass will create a new style class.

In longer, see Guido's Unifying types and classes in Python 2.2.

And, in general, it's a good idea to get into the habit of making all your classes new-style, because some things (the @property decorator is one that comes to mind) won't work with old-style classes.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值