Lists in Python

前端 未结 7 2131
太阳男子
太阳男子 2021-01-07 05:20

Is the List in python homogeneous or heterogeneous?

7条回答
  •  别那么骄傲
    2021-01-07 05:50

    It depends if you talk about the direct elements of a list or its indirect elements.

    I believe that a list is in reality a list of references, not of objects, and that when the interpeter has to use a list, it knows that in fact it must manipulate the objects to which the references are pointing, not the references themselves: that's the "execution model" of Python, I think.

    • What I call indirect element of a list are the objects that constitute the value of the list.

    • What I call direct elements are the references to these objects that constitutes the implementation of the list.

    So:

    • considered as a list of references, a list is homogenous: all the elements are variables, in the plain sense of variable = chunk of memory whose value can change (while the value of an object never changes)

    • considered as a list of the objects pointed by the references, a list is heterogenous. The innuendo being that their TYPES are heterogenous.

    That's my understanding. I don't know if I am fully right.

提交回复
热议问题