example #1:
class Person(object):
pass
example #2:
class Person:
pass
What does the object declaration do? Should you use it? I have a bunch of programs with both of them and don’t know the difference it is making. If anyone can explain this concept please.
In Python2, declaring
objectas the base class makes the class a new-style class. Otherwise, it is a “classic” class. Among the differences are thatProperties only work with new-style classes
new-style classes have the
mromethodnew-style classes have many attributes that classic classes lack
Classic classes are retained in Python2 only for backwards compatibility. All custom classes you define should be made new-style.
In Python3, all classes are new-style, so it need not be explicitly declared there.