Python TIL: the type base class.

From Python 3 onwards, every class by default is an instance of the type class.

>>> class A:
...    pass
>>> isinstance(A, type)

Some more playing around if that’s your thing:

>>> type(A)
<class 'type'>

>>> type.__bases__
(<class 'object'>,)

>>> type(object)
<class 'type'>

>>> issubclass(A, type)

I discovered this while reading through a Django snippet and re-writing some Python 2 code into Python 3. Who knew reading code helps you learn?


Comment via email.