0

Why in python Class inherit Object? [python]

Can we inherit Object of our Class same way? If yes how does it gonna work?

20th Sep 2021, 2:40 PM
I Am a Baked Potato
I Am a Baked Potato - avatar
4 Respostas
+ 3
print(dir(object())) Should print the class methods. As I understand it, every class will inherit implicitly from object. According to the documentation, object() returns "a new featureless object. object is a base for all classes. It has the methods that are common to all instances of Python classes." https://docs.python.org/3/library/functions.html?highlight=object#object
21st Sep 2021, 6:27 AM
Lisa
Lisa - avatar
+ 2
Do you mean something like this? class MyClass(object) I quote from a stackoverflow answers: "In Python 3: inherit from object if you are writing code that tries to be Python agnostic, that is, it needs to work both in Python 2 and in Python 3. Otherwise don't, it really makes no difference since Python inserts it for you behind the scenes." https://stackoverflow.com/questions/4015417/why-do-python-classes-inherit-object#45062077
20th Sep 2021, 6:46 PM
Lisa
Lisa - avatar
+ 1
Lisa Helpful thanks dear!
21st Sep 2021, 1:46 PM
I Am a Baked Potato
I Am a Baked Potato - avatar
0
Lisa Yes I meant for this one! Thanks for link 👍 nice explanation out there. Well I still wonder what properties it going to inherit from object? Can we implement like this with our Class?
21st Sep 2021, 6:14 AM
I Am a Baked Potato
I Am a Baked Potato - avatar