Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 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
asked Feb 16, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer
0 votes
4 answers
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!

30.5k questions

32.5k answers

500 comments

108k users

Browse Categories

...