Try to run the code after running the code that you sent
>>> testlist = list()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'mlist' object is not callable
Now determine the type using the code I posted
>>> type([])
<type 'list'>
>>> type(list)
<class '__main__.mlist'>
>>> type(testlist)
<type 'list'>
It seems that it []creates list, and not mlist, it looks strange: S
Update
-, dis,
>>> import dis
>>> def code1():
... return []
...
>>> dis.dis(code1)
2 0 BUILD_LIST 0
3 RETURN_VALUE
>>> def code2():
... return list()
...
>>> dis.dis(code2)
2 0 LOAD_GLOBAL 0 (list)
3 CALL_FUNCTION 0
6 RETURN_VALUE
, list , , [] BUILD_LIST -. , [] list, [] .
2
Python
>>> class NewList(list):
... pass
...
>>> a = NewList()
>>> a.append(23)
>>> a[0]
23
>>> def double_getitem(self, key):
... return list.__getitem__(self, key) * 2
...
>>> NewList.__getitem__ = double_getitem
>>> a[0]
46
, , list
>>> list.__getitem__ = double_getitem
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't set attributes of built-in/extension type 'list'