[1,2].__class__
{"a": 1, "b": 2}.__class__
5.668.__class__
As we mentioned earlier, everthing in Python is object, the types float, dict, list etc are subclasses of object. Let us see this:
import inspect #inspect module helps to get the heirarchy (method resoultion order) of the resolution of objects
inspect.getmro(type(5.668))
Above, we could see that float type is subclass of object class. Other way to see this is to find on what class the subclass type float is based and what order they are resolved.
print(5.668.__class__.__bases__)
print(5.668.__class__.__mro__)
Here is another interesting one. The bool type. We know it represents True or False, it is based on type int and int is based on object. Let us see that:
print(1==1)
print((1==1).__class__)
print((1==1).__class__.__bases__)
print((1==1).__class__.__bases__[0].__bases__)
True, False, bool are names that are created by python.
print(True.__class__)
print(True.__class__.__bases__)
print(True.__class__.__bases__[0].__bases__)
print(True.__class__ == (1==1).__class__)
print(True.__class__ is (1==1).__class__)
## the ids are same
print(id(True.__class__), id((1==1).__class__))
What about built-in functions? class? type? object?
print(len)
print(len.__class__)
print(len.__class__.__mro__)
Built-in functions are objects too and thay have their class as 'builtin_function_or_method' which is subclass of 'object'.
Recap: Everthing is object. Every object has value, type, base classes, unique id, and attributes. We can create more objects by calling other callable objects.
Reference: Stuart Williams - Python Epiphanies - PyCon 2018 https://www.youtube.com/watch?v=-kqZtZj4Ky0&t=498s