根据我看过的资料,python中list数据结构是用数组实现的。但是,python 列表可以包含不同类型的对象。如果它的底层数据结构是数组,那么数组如何包含不同类型的对象?
数组是特定数据类型我错了吗?
请您参考如下方法:
Python 列表存储对数据的引用,而不是数据本身。直接来自 python 源代码 object.h :
Objects are always accessed through pointers of the type 'PyObject *'. The type 'PyObject' is a structure that only contains the reference count and the type pointer. The actual memory allocated for an object contains other data that can only be accessed after casting the pointer to a pointer to a longer structure type.
如果您需要更详细的信息,源代码中的注释是详细的和描述性的。
