0 votes
1 view
in Python by (47.8k points)

Is there any reason for a class declaration to inherit from an object?

I just found some code that does this and I can't find a good reason why.

class MyClass(object): 

       # class code follows...

1 Answer

0 votes
by (107k points)

Yes, there is a reason for a class declaration to inherit from an object :-

The class style in Python 3.x:

class MyClass(object): = new-style class

class MyClass: = OLD-STYLE CLASS

Explanation:

At the time of the base class definition in Python 3.x, you’re allowed to drop the object from the definition. However, this can open the door for a seriously hard to track problem.

New-style classes are introduced in Python, and by now old-style classes are really quite old. Discussion of old-style classes are buried in the 2.x docs, and they do not exist in Python 3.x.

 

 




 

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 6, 2019 in Python by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...