What is builtins.object?

Question:

What is the meaning of builtins.object in the output?

class Fruits:
    p=12
    def __init__(self,name,color,taste):
        self.name=name
        self.color=color
        self.taste=taste
    def show(self):
        return f"Fruit name: {self.name}nFruit color: {self.color}nFruit taste: {self.taste}"
class Apple(Fruits):
    pass
obj1=Apple(3,3,3)
print(help(Apple))

Output:

Help on class Apple in module __main__:

class Apple(Fruits)
 |  Apple(name, color, taste)
 |  
 |  Method resolution order:
 |      Apple
 |      Fruits
 |      **builtins.object # What is the meaning of builtins.object?**
 |  
 |  Methods inherited from Fruits:
 |  
 |  __init__(self, name, color, taste)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  show(self)
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from Fruits:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes inherited from Fruits:
 |  
 |  p = 12
Asked By: Ali Murtaza

||

Answers:

Essentially, this is showing you that this class is of type object from the builtins of Python.

For some additional information:

Method resolution order:
 |      Apple
 |      Fruits
 |      **builtins.object

What it is fully telling you is that the inheritance order of this class will first resolve methods of the Apple class, if a method is called; then, if it can’t resolve it in the Apple class (i.e. it doesn’t exist) it’ll look for it and resolve it based on definitions in the Fruits class and, lastly, look for it in **builtins.object, which is the archetype for all objects in Python.

Answered By: Karina D.

object is the base for all classes. All classes inherit from it.

Essentially, it has a lot of default functions, like this:

class object:
    def __init__(self):
        pass
    def __str__(self):
        return f'<{type(self).__name__} object at 0x000000000000>'
    def __repr__(self):
        return f'<{type(self).__name__} object at 0x000000000000>'

And when you define a class, class Foo:, it is equivalent to saying class Foo(object):

All classess inherit these default functions from object.

When it shows this in help

Method resolution order:
 |      Apple
 |      Fruits
 |      **builtins.object

It’s showing the inheritance order. That means Apple inherits from Fruits, which inherits from object

Answered By: The Thonnu
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.