为什么python中的列表可以用append增加元素 列表的内存是像数组一样物理连续还是靠指针像链表一样分配

如题 为什么python中的列表可以用append增加元素 列表的内存是像数组一样物理连续还是靠指针像链表一样分配。想知道这个函数是用什么封装起来的 谢谢啦


list_test = []

for i in range(100):
    list_test.append(i)

for l in list_test:
    print(id(l), l)


按这样测试 , 列表append增加元素 , 是指针链表分配。

第二个问题, 去研究 python 编译器代码。

从 builtins.py 开始


class list(object):
    """
    Built-in mutable sequence.

    If no argument is given, the constructor creates a new empty list.
    The argument must be an iterable if specified.
    """
    def append(self, *args, **kwargs): # real signature unknown
        """ Append object to the end of the list. """
        pass