2

I understand that str, int, float, list, tuple are classes, and that they are instance of the default metaclass - type. But what exactly is the 'object' class? At first I thought it was a class like str and int, only that it automatically bequeaths to all classes. But then I saw that the metaclass type both inherited from him and bequeathed to him:

print (isinstance (type, object))
print (isinstance (object, type))

output:

True
True

why is it? How its posible? What exactly is the 'object' class? And what is the difference between it and the metaclass type? If 'object' is a class so what is the metaclass of him?

Roby
  • 21
  • 3
  • 2
    In a way, it makes perfect sense though: `object` is a (base) type, and `type` (the builtin) is an object (everything in Python is first-class and thus can be treated as an object). – kwkt Jan 10 '21 at 17:56
  • 1
    Does this answer your question? [What are Python's type "objects" exactly?](https://stackoverflow.com/questions/23197122/what-are-pythons-type-objects-exactly) – buran Jan 10 '21 at 18:01
  • Also https://stackoverflow.com/questions/56310092/what-is-an-object-in-python – buran Jan 10 '21 at 18:02
  • @buran No, When I say object I mean to the class called 'object'. Not for objects in general in python. but thanks for trying help – Roby Jan 10 '21 at 18:12
  • Check this one https://stackoverflow.com/questions/100003/what-are-metaclasses-in-python Hope it will help, especially the most-upvoted community answer. I retracted my close vote. – buran Jan 10 '21 at 18:31
  • `object` is the base class of everything in Python. – juanpa.arrivillaga Jan 10 '21 at 18:52
  • @juanpa.arrivillaga So how type heir from him? And what's his metaclass? – Roby Jan 10 '21 at 18:57
  • @Roby what do you mean how? `object` is the base class of *everything* including type. yes, there is a circularity here. – juanpa.arrivillaga Jan 10 '21 at 19:07
  • Note, `type(type) is type`, so *type is an instance of itself*, which is probably even weirder. But these are the fundamentals of the type system. – juanpa.arrivillaga Jan 10 '21 at 19:10

0 Answers0