python3中无区别
首先,在python3中加不加object没有区别,因为实际上在python 3 中已经默认就帮你加载了object了,但是在python2中有区别。
python2中区别
示例:
class Person: #无object
name = "zhangsan"
class Dog(object): #有object
name = "pipi"
if __name__ == "__main__":
x = Person()
print "Person", dir(x)
y = Dog()
print "Dog", dir(y)
结果:
Person ['__doc__', '__module__', 'name']
Dog ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__',
'__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'name']
显而易见,Person类不继承object对象,只拥有了__doc__
, __module__
和 自己定义的name
变量, 也就是说这个类的命名空间只有三个对象可以操作;
Dog类继承了object对象,拥有了好多可操作对象,这些都是类中的高级特性。
参考:https://blog.csdn.net/DeepOscar/article/details/80947155