Lists in Python

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

Is the List in python homogeneous or heterogeneous?

7条回答
  •  感情败类
    2021-01-07 05:58

    Lists in Python can be heterogeneous, but by the general convention it is preferable that they only contain homogeneous elements. Python tuples are the natural data structure for heterogeneous sequences.

    Of course you can argue that both tuples and lists are just homogeneous sequences of Python objects, but that is a misleading oversimplification and doesn't add any value.

    Since tuples are immutable and lists are mutable you could also argue that mutability is the real distinction between them. However, that is not how they were intended. More on this can be found in this question.

提交回复
热议问题