0
Why in python Class inherit Object? [python]
Can we inherit Object of our Class same way? If yes how does it gonna work?
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
+ 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
+ 1
Lisa Helpful thanks dear!
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?