Lists are mutable sequences, typically used to store collections of homogeneous items (where the precise degree of similarity will vary by application).
Tuples are immutable sequences, typically used to store collections of heterogeneous data (such as the 2-tuples produced by the enumerate() built-in). Tuples are also used for cases where an immutable sequence of homogeneous data is needed (such as allowing storage in a set or dict instance).
在Python中,列表和元组基本相同,只是列表是可变的,元组是可变的。列表和元组可以是同构的,也可以是异构的。
如果您想要具有强制同质性的序列,请使用
array
模块或使用NumPy。文件
从Python Documentation for sequence types:
相关问题 更多 >
编程相关推荐