Here x
is an instance of class list
, in new style classes type()
returns the class of the instance itself, i.e list
in this case. Consider this simple example:
>>> class A(object):
pass
...
>>> type(A()) #calling type on the instance returns its class
<class '__main__.A'>
>>> type(A()) is A
True
Note that the above example will not work for user defined old-style classes as all the instances there were of type instance
.
>>> class A:
pass
...
>>> type(A())
<type 'instance'>