Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k 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 (106k 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
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 6, 2019 in Python by Sammy (47.6k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...