I'm a bit confused about types and classes in Python. For e.g. the following REPL conversation confuses me:
>>> class A: pass
...
>>> a = A()
>>> type(a)
<type 'instance'>
>>> a.__class__
<class __main__.A at 0xb770756c>
>>> type([])
<type 'list'>
>>> [].__class__
<type 'list'>
>>> type(list)
<type 'type'>
>>> list.__class__
<type 'type'>
>>> type(A)
<type 'classobj'>
>>> A.__class__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: class A has no attribute '__class__'
- Why is the type and class for inbuilt things (e.g. list here) the same but different for user classes/types?
- Isn't every class an instance of some other class (like Class in Java)? Why no
__class__
for user defined classes?
Any explanation/further reading which can clarify this behaviour would be much appreciated. TIA.